Exemplo n.º 1
0
 // Test Group creation before AUDIT process
 private void testGroupCreationBeforeAudit(DeviceId deviceId) {
   PortNumber[] ports1 = {PortNumber.portNumber(31), PortNumber.portNumber(32)};
   PortNumber[] ports2 = {PortNumber.portNumber(41), PortNumber.portNumber(42)};
   GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
   List<GroupBucket> buckets = new ArrayList<>();
   List<PortNumber> outPorts = new ArrayList<>();
   outPorts.addAll(Arrays.asList(ports1));
   outPorts.addAll(Arrays.asList(ports2));
   for (PortNumber portNumber : outPorts) {
     TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
     tBuilder
         .setOutput(portNumber)
         .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
         .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
         .pushMpls()
         .setMpls(MplsLabel.mplsLabel(106));
     buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
   }
   GroupBuckets groupBuckets = new GroupBuckets(buckets);
   GroupDescription newGroupDesc =
       new DefaultGroupDescription(deviceId, Group.Type.SELECT, groupBuckets, key, null, appId);
   groupService.addGroup(newGroupDesc);
   assertEquals(null, groupService.getGroup(deviceId, key));
   assertEquals(0, Iterables.size(groupService.getGroups(deviceId, appId)));
 }
Exemplo n.º 2
0
  /**
   * Remove VLAN tag and packet out to given port.
   *
   * <p>Note: In current implementation, we expect all communication with end hosts within a subnet
   * to be untagged.
   *
   * <p>For those pipelines that internally assigns a VLAN, the VLAN tag will be removed before
   * egress.
   *
   * <p>For those pipelines that do not assign internal VLAN, the packet remains untagged.
   *
   * @param packet packet to be forwarded
   * @param outPort where the packet should be forwarded
   */
  private void removeVlanAndForward(Ethernet packet, ConnectPoint outPort) {
    packet.setEtherType(Ethernet.TYPE_ARP);
    packet.setVlanID(Ethernet.VLAN_UNTAGGED);
    ByteBuffer buf = ByteBuffer.wrap(packet.serialize());

    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
    tbuilder.setOutput(outPort.port());
    srManager.packetService.emit(
        new DefaultOutboundPacket(outPort.deviceId(), tbuilder.build(), buf));
  }
Exemplo n.º 3
0
  // Test group add bucket operations
  private void testAddBuckets(DeviceId deviceId) {
    GroupKey addKey = new DefaultGroupKey("group1AddBuckets".getBytes());

    GroupKey prevKey = new DefaultGroupKey("group1BeforeAudit".getBytes());
    Group createdGroup = groupService.getGroup(deviceId, prevKey);
    List<GroupBucket> buckets = new ArrayList<>();
    buckets.addAll(createdGroup.buckets().buckets());

    PortNumber[] addPorts = {PortNumber.portNumber(51), PortNumber.portNumber(52)};
    List<PortNumber> outPorts;
    outPorts = new ArrayList<>();
    outPorts.addAll(Arrays.asList(addPorts));
    List<GroupBucket> addBuckets;
    addBuckets = new ArrayList<>();
    for (PortNumber portNumber : outPorts) {
      TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
      tBuilder
          .setOutput(portNumber)
          .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
          .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
          .pushMpls()
          .setMpls(MplsLabel.mplsLabel(106));
      addBuckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
      buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
    }
    GroupBuckets groupAddBuckets = new GroupBuckets(addBuckets);
    groupService.addBucketsToGroup(deviceId, prevKey, groupAddBuckets, addKey, appId);
    GroupBuckets updatedBuckets = new GroupBuckets(buckets);
    List<GroupOperation> expectedGroupOps =
        Collections.singletonList(
            GroupOperation.createModifyGroupOperation(
                createdGroup.id(), Group.Type.SELECT, updatedBuckets));
    if (deviceId.equals(DID)) {
      internalProvider.validate(deviceId, expectedGroupOps);
    } else {
      this.validate(deviceId, expectedGroupOps);
    }
    Group existingGroup = groupService.getGroup(deviceId, addKey);
    List<Group> groupEntries = Collections.singletonList(existingGroup);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
  }
Exemplo n.º 4
0
  private Group createSouthboundGroupEntry(
      GroupId gId, List<PortNumber> ports, long referenceCount, DeviceId deviceId) {
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.addAll(ports);

    List<GroupBucket> buckets = new ArrayList<>();
    for (PortNumber portNumber : outPorts) {
      TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
      tBuilder
          .setOutput(portNumber)
          .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
          .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
          .pushMpls()
          .setMpls(MplsLabel.mplsLabel(106));
      buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
    }
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    StoredGroupEntry group = new DefaultGroup(gId, deviceId, Group.Type.SELECT, groupBuckets);
    group.setReferenceCount(referenceCount);
    return group;
  }
Exemplo n.º 5
0
  private void populateGatewayIcmpRule(Ip4Address gatewayIp, DeviceId deviceId) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();

    sBuilder
        .matchEthType(Ethernet.TYPE_IPV4)
        .matchIPProtocol(IPv4.PROTOCOL_ICMP)
        .matchIPDst(gatewayIp.toIpPrefix());

    tBuilder.setOutput(PortNumber.CONTROLLER);

    ForwardingObjective fo =
        DefaultForwardingObjective.builder()
            .withSelector(sBuilder.build())
            .withTreatment(tBuilder.build())
            .withPriority(GATEWAY_ICMP_PRIORITY)
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .fromApp(appId)
            .add();

    flowObjectiveService.forward(deviceId, fo);
  }
Exemplo n.º 6
0
  private void populateGatewayToController(long vni, String subNetCidr) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();

    sBuilder
        .matchEthType(Ethernet.TYPE_IPV4)
        .matchTunnelId(vni)
        .matchIPSrc(IpPrefix.valueOf(subNetCidr))
        .matchEthDst(Constants.DEFAULT_GATEWAY_MAC);
    tBuilder.setOutput(PortNumber.CONTROLLER);

    ForwardingObjective fo =
        DefaultForwardingObjective.builder()
            .withSelector(sBuilder.build())
            .withTreatment(tBuilder.build())
            .withFlag(ForwardingObjective.Flag.VERSATILE)
            .withPriority(ROUTING_RULE_PRIORITY)
            .fromApp(appId)
            .add();

    gatewayService
        .getGatewayDeviceIds()
        .forEach(deviceId -> flowObjectiveService.forward(deviceId, fo));
  }
Exemplo n.º 7
0
  private void groupOperationFaliure(DeviceId deviceId) {
    PortNumber[] ports1 = {PortNumber.portNumber(31), PortNumber.portNumber(32)};
    PortNumber[] ports2 = {PortNumber.portNumber(41), PortNumber.portNumber(42)};
    // Test Group creation before AUDIT process
    GroupKey key = new DefaultGroupKey("group1BeforeAudit".getBytes());
    List<GroupBucket> buckets = new ArrayList<>();
    List<PortNumber> outPorts = new ArrayList<>();
    outPorts.addAll(Arrays.asList(ports1));
    outPorts.addAll(Arrays.asList(ports2));
    for (PortNumber portNumber : outPorts) {
      TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
      tBuilder
          .setOutput(portNumber)
          .setEthDst(MacAddress.valueOf("00:00:00:00:00:02"))
          .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01"))
          .pushMpls()
          .setMpls(MplsLabel.mplsLabel(106));
      buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build()));
    }
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    GroupDescription newGroupDesc =
        new DefaultGroupDescription(deviceId, Group.Type.SELECT, groupBuckets, key, null, appId);
    groupService.addGroup(newGroupDesc);

    // Test initial group audit process
    GroupId gId1 = new DefaultGroupId(1);
    Group group1 = createSouthboundGroupEntry(gId1, Arrays.asList(ports1), 0, deviceId);
    GroupId gId2 = new DefaultGroupId(2);
    // Non zero reference count will make the group manager to queue
    // the extraneous groups until reference count is zero.
    Group group2 = createSouthboundGroupEntry(gId2, Arrays.asList(ports2), 2, deviceId);
    List<Group> groupEntries = Arrays.asList(group1, group2);
    providerService.pushGroupMetrics(deviceId, groupEntries);
    Group createdGroup = groupService.getGroup(deviceId, key);

    // Group Add failure test
    GroupOperation groupAddOp =
        GroupOperation.createAddGroupOperation(
            createdGroup.id(), createdGroup.type(), createdGroup.buckets());
    providerService.groupOperationFailed(deviceId, groupAddOp);
    internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_ADD_FAILED));

    // Group Mod failure test
    groupService.addGroup(newGroupDesc);
    createdGroup = groupService.getGroup(deviceId, key);
    assertNotNull(createdGroup);

    GroupOperation groupModOp =
        GroupOperation.createModifyGroupOperation(
            createdGroup.id(), createdGroup.type(), createdGroup.buckets());
    providerService.groupOperationFailed(deviceId, groupModOp);
    internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATE_FAILED));

    // Group Delete failure test
    groupService.addGroup(newGroupDesc);
    createdGroup = groupService.getGroup(deviceId, key);
    assertNotNull(createdGroup);

    GroupOperation groupDelOp =
        GroupOperation.createDeleteGroupOperation(createdGroup.id(), createdGroup.type());
    providerService.groupOperationFailed(deviceId, groupDelOp);
    internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_REMOVE_FAILED));
  }