コード例 #1
0
ファイル: OltPipeline.java プロジェクト: sauravdas2/onos-fork
  private void buildAndApplyRule(
      FilteringObjective filter, TrafficSelector selector, TrafficTreatment treatment) {
    FlowRule rule =
        DefaultFlowRule.builder()
            .forDevice(deviceId)
            .forTable(0)
            .fromApp(filter.appId())
            .makePermanent()
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(filter.priority())
            .build();

    FlowRuleOperations.Builder opsBuilder = FlowRuleOperations.builder();

    switch (filter.type()) {
      case PERMIT:
        opsBuilder.add(rule);
        break;
      case DENY:
        opsBuilder.remove(rule);
        break;
      default:
        log.warn("Unknown filter type : {}", filter.type());
        fail(filter, ObjectiveError.UNSUPPORTED);
    }

    applyFlowRules(opsBuilder, filter);
  }
コード例 #2
0
ファイル: DemoInstaller.java プロジェクト: rsmontero/onos
    @Override
    public JsonNode call() throws Exception {
      ObjectNode node = mapper.createObjectNode();
      CountDownLatch latch = new CountDownLatch(1);
      flowService.apply(
          adds.build(
              new FlowRuleOperationsContext() {

                private final Stopwatch timer = Stopwatch.createStarted();

                @Override
                public void onSuccess(FlowRuleOperations ops) {

                  long elapsed = timer.elapsed(TimeUnit.MILLISECONDS);
                  node.put("elapsed", elapsed);

                  latch.countDown();
                }
              }));

      latch.await(10, TimeUnit.SECONDS);
      if (this.remove) {
        flowService.apply(removes.build());
      }
      return node;
    }
コード例 #3
0
ファイル: DemoInstaller.java プロジェクト: rsmontero/onos
    private void prepareInstallation() {
      Set<ControllerNode> instances = Sets.newHashSet(clusterService.getNodes());
      instances.remove(clusterService.getLocalNode());
      Set<NodeId> acceptableNodes = Sets.newHashSet();
      if (neighbours >= instances.size()) {
        instances.forEach(instance -> acceptableNodes.add(instance.id()));
      } else {
        Iterator<ControllerNode> nodes = instances.iterator();
        for (int i = neighbours; i > 0; i--) {
          acceptableNodes.add(nodes.next().id());
        }
      }
      acceptableNodes.add(clusterService.getLocalNode().id());

      Set<Device> devices = Sets.newHashSet();
      for (Device dev : deviceService.getDevices()) {
        if (acceptableNodes.contains(mastershipService.getMasterFor(dev.id()))) {
          devices.add(dev);
        }
      }

      TrafficTreatment treatment =
          DefaultTrafficTreatment.builder()
              .setOutput(PortNumber.portNumber(RandomUtils.nextInt()))
              .build();
      TrafficSelector.Builder sbuilder;
      FlowRuleOperations.Builder rules = FlowRuleOperations.builder();
      FlowRuleOperations.Builder remove = FlowRuleOperations.builder();

      for (Device d : devices) {
        for (int i = 0; i < this.flowPerDevice; i++) {
          sbuilder = DefaultTrafficSelector.builder();

          sbuilder
              .matchEthSrc(MacAddress.valueOf(RandomUtils.nextInt() * i))
              .matchEthDst(MacAddress.valueOf((Integer.MAX_VALUE - i) * RandomUtils.nextInt()));

          int randomPriority = RandomUtils.nextInt();
          FlowRule f =
              DefaultFlowRule.builder()
                  .forDevice(d.id())
                  .withSelector(sbuilder.build())
                  .withTreatment(treatment)
                  .withPriority(randomPriority)
                  .fromApp(appId)
                  .makeTemporary(10)
                  .build();
          rules.add(f);
          remove.remove(f);
        }
      }

      this.adds = rules;
      this.removes = remove;
    }
コード例 #4
0
ファイル: OltPipeline.java プロジェクト: sauravdas2/onos-fork
  private void processMulticastRule(ForwardingObjective fwd) {
    if (fwd.nextId() == null) {
      log.error("Multicast objective does not have a next id");
      fail(fwd, ObjectiveError.BADPARAMS);
    }

    OLTPipelineGroup next = getGroupForNextObjective(fwd.nextId());

    if (next == null) {
      log.error("Group for forwarding objective missing: {}", fwd);
      fail(fwd, ObjectiveError.GROUPMISSING);
    }

    Group group = groupService.getGroup(deviceId, next.key());
    TrafficTreatment treatment = buildTreatment(Instructions.createGroup(group.id()));

    FlowRule rule =
        DefaultFlowRule.builder()
            .forDevice(deviceId)
            .forTable(0)
            .fromApp(fwd.appId())
            .makePermanent()
            .withPriority(fwd.priority())
            .withSelector(fwd.selector())
            .withTreatment(treatment)
            .build();

    FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
    switch (fwd.op()) {
      case ADD:
        builder.add(rule);
        break;
      case REMOVE:
        builder.remove(rule);
        break;
      case ADD_TO_EXISTING:
      case REMOVE_FROM_EXISTING:
        break;
      default:
        log.warn("Unknown forwarding operation: {}", fwd.op());
    }

    applyFlowRules(builder, fwd);
  }
コード例 #5
0
ファイル: OltPipeline.java プロジェクト: sauravdas2/onos-fork
  private void applyRules(ForwardingObjective fwd, FlowRule.Builder inner, FlowRule.Builder outer) {
    FlowRuleOperations.Builder builder = FlowRuleOperations.builder();
    switch (fwd.op()) {
      case ADD:
        builder.add(inner.build()).add(outer.build());
        break;
      case REMOVE:
        builder.remove(inner.build()).remove(outer.build());
        break;
      case ADD_TO_EXISTING:
        break;
      case REMOVE_FROM_EXISTING:
        break;
      default:
        log.warn("Unknown forwarding operation: {}", fwd.op());
    }

    applyFlowRules(builder, fwd);
  }
コード例 #6
0
ファイル: OltPipeline.java プロジェクト: sauravdas2/onos-fork
  private void applyFlowRules(FlowRuleOperations.Builder builder, Objective objective) {
    flowRuleService.apply(
        builder.build(
            new FlowRuleOperationsContext() {
              @Override
              public void onSuccess(FlowRuleOperations ops) {
                pass(objective);
              }

              @Override
              public void onError(FlowRuleOperations ops) {
                fail(objective, ObjectiveError.FLOWINSTALLATIONFAILED);
              }
            }));
  }