@Test public void syncGroups_externalEpsWithoutLocation() throws Exception { EndpointBuilder endpointBuilder = buildEndpoint(IPV4_0, MAC_0, new NodeConnectorId(OPENFLOW + CONNECTOR_0.getValue())); endpointBuilder.setNetworkContainment(SUBNET_1); Endpoint endpoint = endpointBuilder.build(); when(ctx.getTenant(any(TenantId.class))).thenReturn(getTestIndexedTenant()); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); Preconditions.checkNotNull(ordinals); Set<EgKey> egKeys = new HashSet<>(); egKeys.add(new EgKey(buildTenant().getId(), endpoint.getEndpointGroup())); Set<NodeConnectorId> externalPorts = new HashSet<>(); externalPorts.add(new NodeConnectorId(OPENFLOW + CONNECTOR_1.getValue())); externalPorts.add(CONNECTOR_2); Collection<Endpoint> endpoints = new HashSet<>(); EndpointBuilder noLocEndpointBuilder = buildEndpoint(IPV4_1, MAC_1, CONNECTOR_1); endpoints.add(noLocEndpointBuilder.build()); when(ctx.getSwitchManager()).thenReturn(switchManager); when(endpointManager.getGroupsForNode(NODE_ID)).thenReturn(egKeys); when(endpointManager.getExtEpsNoLocForGroup(any(EgKey.class))).thenReturn(endpoints); when(switchManager.getExternalPorts(NODE_ID)).thenReturn(externalPorts); groupTable.syncGroups(NODE_ID, ordinals, endpoint, GROUP_ID, ofWriter); InOrder order = inOrder(endpointManager, policyInfo, switchManager, ofWriter); order.verify(endpointManager, times(1)).getGroupsForNode(NODE_ID); order.verify(endpointManager, times(1)).getExtEpsNoLocForGroup(any(EgKey.class)); order.verify(switchManager, times(1)).getExternalPorts(any(NodeId.class)); order.verify(ofWriter, times(1)).writeBucket(any(NodeId.class), any(GroupId.class), any(Bucket.class)); }
@VisibleForTesting void syncGroups(NodeId nodeId, EndpointFwdCtxOrdinals ordinals, Endpoint endpoint, GroupId groupId, OfWriter ofWriter) throws Exception { for (EgKey endpointGroupKey : ctx.getEndpointManager().getGroupsForNode(nodeId)) { for (NodeId destinationNode : findPeerNodesForGroup(endpointGroupKey)) { if (nodeId.equals(destinationNode)) continue; if (isFloodDomainOnNode(ordinals.getFdId(), destinationNode)) { Long bucketId; try { bucketId = (long) OrdinalFactory.getContextOrdinal(destinationNode); } catch (Exception e) { LOG.error("Error during getting of context ordinal, node: {}", destinationNode); continue; } bucketId |= 1L << 31; IpAddress tunDst = ctx.getSwitchManager().getTunnelIP(destinationNode, TunnelTypeVxlan.class); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunDst == null || tunPort == null) continue; Action tunDstAction; if (tunDst.getIpv4Address() != null) { String nextHop = tunDst.getIpv4Address().getValue(); tunDstAction = nxLoadTunIPv4Action(nextHop, true); } else { LOG.error("IPv6 tunnel destination {} for {} not supported", tunDst.getIpv6Address().getValue(), destinationNode); continue; } BucketBuilder bucketBuilder = new BucketBuilder().setBucketId(new BucketId(bucketId)) .setAction(actionList(tunDstAction, outputAction(tunPort))); ofWriter.writeBucket(nodeId, groupId, bucketBuilder.build()); } } OfOverlayContext ofc = endpoint.getAugmentation(OfOverlayContext.class); if (EndpointManager.isExternal(endpoint, ctx.getTenant(endpoint.getTenant()).getExternalImplicitGroups())) continue; long bucketId; try { bucketId = getOfPortNum(ofc.getNodeConnectorId()); } catch (NumberFormatException e) { LOG.warn("Could not parse port number {}", ofc.getNodeConnectorId(), e); continue; } Action output = outputAction(ofc.getNodeConnectorId()); BucketBuilder bb = new BucketBuilder().setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(output)); ofWriter.writeBucket(nodeId, groupId, bb.build()); for (Endpoint extEp : ctx.getEndpointManager().getExtEpsNoLocForGroup(endpointGroupKey)) { if (extEp.getNetworkContainment() != null && extEp.getNetworkContainment().equals(endpoint.getNetworkContainment())) { Subnet subnet = ctx.getTenant(extEp.getTenant()).resolveSubnet(new SubnetId(extEp.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(extEp.getTenant()) .resolveL2FloodDomain(new L2FloodDomainId(subnet.getParent().getValue())); if (l2Fd != null) { Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); for (NodeConnectorId extNcId : ctx.getSwitchManager().getExternalPorts(nodeId)) { try { bucketId = getOfPortNum(extNcId); } catch (NumberFormatException e) { LOG.warn("Could not parse external port number {}", extNcId, e); continue; } ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actionList = new ArrayList<>(); if (segmentation != null) { Integer vlanId = segmentation.getSegmentationId(); actionList.addAll(FlowUtils.pushVlanActions(vlanId)); actionList.add(new ActionBuilder().setOrder(2).setAction(outputAction(extNcId))); } else { actionList.add(new ActionBuilder().setOrder(0).setAction(outputAction(extNcId))); } bb.setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(actionList)); ofWriter.writeBucket(nodeId, groupId, bb.build()); } } } } } }
GroupTable extends OfTable { @VisibleForTesting void syncGroups(NodeId nodeId, EndpointFwdCtxOrdinals ordinals, Endpoint endpoint, GroupId groupId, OfWriter ofWriter) throws Exception { for (EgKey endpointGroupKey : ctx.getEndpointManager().getGroupsForNode(nodeId)) { for (NodeId destinationNode : findPeerNodesForGroup(endpointGroupKey)) { if (nodeId.equals(destinationNode)) continue; if (isFloodDomainOnNode(ordinals.getFdId(), destinationNode)) { Long bucketId; try { bucketId = (long) OrdinalFactory.getContextOrdinal(destinationNode); } catch (Exception e) { LOG.error("Error during getting of context ordinal, node: {}", destinationNode); continue; } bucketId |= 1L << 31; IpAddress tunDst = ctx.getSwitchManager().getTunnelIP(destinationNode, TunnelTypeVxlan.class); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunDst == null || tunPort == null) continue; Action tunDstAction; if (tunDst.getIpv4Address() != null) { String nextHop = tunDst.getIpv4Address().getValue(); tunDstAction = nxLoadTunIPv4Action(nextHop, true); } else { LOG.error("IPv6 tunnel destination {} for {} not supported", tunDst.getIpv6Address().getValue(), destinationNode); continue; } BucketBuilder bucketBuilder = new BucketBuilder().setBucketId(new BucketId(bucketId)) .setAction(actionList(tunDstAction, outputAction(tunPort))); ofWriter.writeBucket(nodeId, groupId, bucketBuilder.build()); } } OfOverlayContext ofc = endpoint.getAugmentation(OfOverlayContext.class); if (EndpointManager.isExternal(endpoint, ctx.getTenant(endpoint.getTenant()).getExternalImplicitGroups())) continue; long bucketId; try { bucketId = getOfPortNum(ofc.getNodeConnectorId()); } catch (NumberFormatException e) { LOG.warn("Could not parse port number {}", ofc.getNodeConnectorId(), e); continue; } Action output = outputAction(ofc.getNodeConnectorId()); BucketBuilder bb = new BucketBuilder().setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(output)); ofWriter.writeBucket(nodeId, groupId, bb.build()); for (Endpoint extEp : ctx.getEndpointManager().getExtEpsNoLocForGroup(endpointGroupKey)) { if (extEp.getNetworkContainment() != null && extEp.getNetworkContainment().equals(endpoint.getNetworkContainment())) { Subnet subnet = ctx.getTenant(extEp.getTenant()).resolveSubnet(new SubnetId(extEp.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(extEp.getTenant()) .resolveL2FloodDomain(new L2FloodDomainId(subnet.getParent().getValue())); if (l2Fd != null) { Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); for (NodeConnectorId extNcId : ctx.getSwitchManager().getExternalPorts(nodeId)) { try { bucketId = getOfPortNum(extNcId); } catch (NumberFormatException e) { LOG.warn("Could not parse external port number {}", extNcId, e); continue; } ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actionList = new ArrayList<>(); if (segmentation != null) { Integer vlanId = segmentation.getSegmentationId(); actionList.addAll(FlowUtils.pushVlanActions(vlanId)); actionList.add(new ActionBuilder().setOrder(2).setAction(outputAction(extNcId))); } else { actionList.add(new ActionBuilder().setOrder(0).setAction(outputAction(extNcId))); } bb.setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(actionList)); ofWriter.writeBucket(nodeId, groupId, bb.build()); } } } } } } }
GroupTable extends OfTable { @VisibleForTesting void syncGroups(NodeId nodeId, EndpointFwdCtxOrdinals ordinals, Endpoint endpoint, GroupId groupId, OfWriter ofWriter) throws Exception { for (EgKey endpointGroupKey : ctx.getEndpointManager().getGroupsForNode(nodeId)) { for (NodeId destinationNode : findPeerNodesForGroup(endpointGroupKey)) { if (nodeId.equals(destinationNode)) continue; if (isFloodDomainOnNode(ordinals.getFdId(), destinationNode)) { Long bucketId; try { bucketId = (long) OrdinalFactory.getContextOrdinal(destinationNode); } catch (Exception e) { LOG.error("Error during getting of context ordinal, node: {}", destinationNode); continue; } bucketId |= 1L << 31; IpAddress tunDst = ctx.getSwitchManager().getTunnelIP(destinationNode, TunnelTypeVxlan.class); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunDst == null || tunPort == null) continue; Action tunDstAction; if (tunDst.getIpv4Address() != null) { String nextHop = tunDst.getIpv4Address().getValue(); tunDstAction = nxLoadTunIPv4Action(nextHop, true); } else { LOG.error("IPv6 tunnel destination {} for {} not supported", tunDst.getIpv6Address().getValue(), destinationNode); continue; } BucketBuilder bucketBuilder = new BucketBuilder().setBucketId(new BucketId(bucketId)) .setAction(actionList(tunDstAction, outputAction(tunPort))); ofWriter.writeBucket(nodeId, groupId, bucketBuilder.build()); } } OfOverlayContext ofc = endpoint.getAugmentation(OfOverlayContext.class); if (EndpointManager.isExternal(endpoint, ctx.getTenant(endpoint.getTenant()).getExternalImplicitGroups())) continue; long bucketId; try { bucketId = getOfPortNum(ofc.getNodeConnectorId()); } catch (NumberFormatException e) { LOG.warn("Could not parse port number {}", ofc.getNodeConnectorId(), e); continue; } Action output = outputAction(ofc.getNodeConnectorId()); BucketBuilder bb = new BucketBuilder().setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(output)); ofWriter.writeBucket(nodeId, groupId, bb.build()); for (Endpoint extEp : ctx.getEndpointManager().getExtEpsNoLocForGroup(endpointGroupKey)) { if (extEp.getNetworkContainment() != null && extEp.getNetworkContainment().equals(endpoint.getNetworkContainment())) { Subnet subnet = ctx.getTenant(extEp.getTenant()).resolveSubnet(new SubnetId(extEp.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(extEp.getTenant()) .resolveL2FloodDomain(new L2FloodDomainId(subnet.getParent().getValue())); if (l2Fd != null) { Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); for (NodeConnectorId extNcId : ctx.getSwitchManager().getExternalPorts(nodeId)) { try { bucketId = getOfPortNum(extNcId); } catch (NumberFormatException e) { LOG.warn("Could not parse external port number {}", extNcId, e); continue; } ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actionList = new ArrayList<>(); if (segmentation != null) { Integer vlanId = segmentation.getSegmentationId(); actionList.addAll(FlowUtils.pushVlanActions(vlanId)); actionList.add(new ActionBuilder().setOrder(2).setAction(outputAction(extNcId))); } else { actionList.add(new ActionBuilder().setOrder(0).setAction(outputAction(extNcId))); } bb.setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(actionList)); ofWriter.writeBucket(nodeId, groupId, bb.build()); } } } } } } GroupTable(OfContext ctx); }
GroupTable extends OfTable { @VisibleForTesting void syncGroups(NodeId nodeId, EndpointFwdCtxOrdinals ordinals, Endpoint endpoint, GroupId groupId, OfWriter ofWriter) throws Exception { for (EgKey endpointGroupKey : ctx.getEndpointManager().getGroupsForNode(nodeId)) { for (NodeId destinationNode : findPeerNodesForGroup(endpointGroupKey)) { if (nodeId.equals(destinationNode)) continue; if (isFloodDomainOnNode(ordinals.getFdId(), destinationNode)) { Long bucketId; try { bucketId = (long) OrdinalFactory.getContextOrdinal(destinationNode); } catch (Exception e) { LOG.error("Error during getting of context ordinal, node: {}", destinationNode); continue; } bucketId |= 1L << 31; IpAddress tunDst = ctx.getSwitchManager().getTunnelIP(destinationNode, TunnelTypeVxlan.class); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunDst == null || tunPort == null) continue; Action tunDstAction; if (tunDst.getIpv4Address() != null) { String nextHop = tunDst.getIpv4Address().getValue(); tunDstAction = nxLoadTunIPv4Action(nextHop, true); } else { LOG.error("IPv6 tunnel destination {} for {} not supported", tunDst.getIpv6Address().getValue(), destinationNode); continue; } BucketBuilder bucketBuilder = new BucketBuilder().setBucketId(new BucketId(bucketId)) .setAction(actionList(tunDstAction, outputAction(tunPort))); ofWriter.writeBucket(nodeId, groupId, bucketBuilder.build()); } } OfOverlayContext ofc = endpoint.getAugmentation(OfOverlayContext.class); if (EndpointManager.isExternal(endpoint, ctx.getTenant(endpoint.getTenant()).getExternalImplicitGroups())) continue; long bucketId; try { bucketId = getOfPortNum(ofc.getNodeConnectorId()); } catch (NumberFormatException e) { LOG.warn("Could not parse port number {}", ofc.getNodeConnectorId(), e); continue; } Action output = outputAction(ofc.getNodeConnectorId()); BucketBuilder bb = new BucketBuilder().setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(output)); ofWriter.writeBucket(nodeId, groupId, bb.build()); for (Endpoint extEp : ctx.getEndpointManager().getExtEpsNoLocForGroup(endpointGroupKey)) { if (extEp.getNetworkContainment() != null && extEp.getNetworkContainment().equals(endpoint.getNetworkContainment())) { Subnet subnet = ctx.getTenant(extEp.getTenant()).resolveSubnet(new SubnetId(extEp.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(extEp.getTenant()) .resolveL2FloodDomain(new L2FloodDomainId(subnet.getParent().getValue())); if (l2Fd != null) { Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); for (NodeConnectorId extNcId : ctx.getSwitchManager().getExternalPorts(nodeId)) { try { bucketId = getOfPortNum(extNcId); } catch (NumberFormatException e) { LOG.warn("Could not parse external port number {}", extNcId, e); continue; } ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actionList = new ArrayList<>(); if (segmentation != null) { Integer vlanId = segmentation.getSegmentationId(); actionList.addAll(FlowUtils.pushVlanActions(vlanId)); actionList.add(new ActionBuilder().setOrder(2).setAction(outputAction(extNcId))); } else { actionList.add(new ActionBuilder().setOrder(0).setAction(outputAction(extNcId))); } bb.setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(actionList)); ofWriter.writeBucket(nodeId, groupId, bb.build()); } } } } } } GroupTable(OfContext ctx); @Override void sync(Endpoint endpoint, OfWriter ofWriter); }
GroupTable extends OfTable { @VisibleForTesting void syncGroups(NodeId nodeId, EndpointFwdCtxOrdinals ordinals, Endpoint endpoint, GroupId groupId, OfWriter ofWriter) throws Exception { for (EgKey endpointGroupKey : ctx.getEndpointManager().getGroupsForNode(nodeId)) { for (NodeId destinationNode : findPeerNodesForGroup(endpointGroupKey)) { if (nodeId.equals(destinationNode)) continue; if (isFloodDomainOnNode(ordinals.getFdId(), destinationNode)) { Long bucketId; try { bucketId = (long) OrdinalFactory.getContextOrdinal(destinationNode); } catch (Exception e) { LOG.error("Error during getting of context ordinal, node: {}", destinationNode); continue; } bucketId |= 1L << 31; IpAddress tunDst = ctx.getSwitchManager().getTunnelIP(destinationNode, TunnelTypeVxlan.class); NodeConnectorId tunPort = ctx.getSwitchManager().getTunnelPort(nodeId, TunnelTypeVxlan.class); if (tunDst == null || tunPort == null) continue; Action tunDstAction; if (tunDst.getIpv4Address() != null) { String nextHop = tunDst.getIpv4Address().getValue(); tunDstAction = nxLoadTunIPv4Action(nextHop, true); } else { LOG.error("IPv6 tunnel destination {} for {} not supported", tunDst.getIpv6Address().getValue(), destinationNode); continue; } BucketBuilder bucketBuilder = new BucketBuilder().setBucketId(new BucketId(bucketId)) .setAction(actionList(tunDstAction, outputAction(tunPort))); ofWriter.writeBucket(nodeId, groupId, bucketBuilder.build()); } } OfOverlayContext ofc = endpoint.getAugmentation(OfOverlayContext.class); if (EndpointManager.isExternal(endpoint, ctx.getTenant(endpoint.getTenant()).getExternalImplicitGroups())) continue; long bucketId; try { bucketId = getOfPortNum(ofc.getNodeConnectorId()); } catch (NumberFormatException e) { LOG.warn("Could not parse port number {}", ofc.getNodeConnectorId(), e); continue; } Action output = outputAction(ofc.getNodeConnectorId()); BucketBuilder bb = new BucketBuilder().setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(output)); ofWriter.writeBucket(nodeId, groupId, bb.build()); for (Endpoint extEp : ctx.getEndpointManager().getExtEpsNoLocForGroup(endpointGroupKey)) { if (extEp.getNetworkContainment() != null && extEp.getNetworkContainment().equals(endpoint.getNetworkContainment())) { Subnet subnet = ctx.getTenant(extEp.getTenant()).resolveSubnet(new SubnetId(extEp.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(extEp.getTenant()) .resolveL2FloodDomain(new L2FloodDomainId(subnet.getParent().getValue())); if (l2Fd != null) { Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); for (NodeConnectorId extNcId : ctx.getSwitchManager().getExternalPorts(nodeId)) { try { bucketId = getOfPortNum(extNcId); } catch (NumberFormatException e) { LOG.warn("Could not parse external port number {}", extNcId, e); continue; } ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder> actionList = new ArrayList<>(); if (segmentation != null) { Integer vlanId = segmentation.getSegmentationId(); actionList.addAll(FlowUtils.pushVlanActions(vlanId)); actionList.add(new ActionBuilder().setOrder(2).setAction(outputAction(extNcId))); } else { actionList.add(new ActionBuilder().setOrder(0).setAction(outputAction(extNcId))); } bb.setBucketId(new BucketId(bucketId)).setAction( FlowUtils.actionList(actionList)); ofWriter.writeBucket(nodeId, groupId, bb.build()); } } } } } } GroupTable(OfContext ctx); @Override void sync(Endpoint endpoint, OfWriter ofWriter);  }