예제 #1
0
  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
    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;
    }
예제 #3
0
  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);
  }
예제 #4
0
  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);
  }