@Test public void testSync() throws Exception { Set<Long> externalPorts = new HashSet<>(); externalPorts.add(Long.valueOf(CONNECTOR_1.getValue())); TenantBuilder tenantBuilder = buildTenant(); tenantBuilder.setForwardingContext(new ForwardingContextBuilder() .setL2FloodDomain(getL2FloodDomainList(true)) .setL2BridgeDomain(getL2BridgeDomainList()) .setL3Context(getL3ContextList()) .setSubnet(getSubnetList()).build()) .build().getId(); Tenant tenant = tenantBuilder.build(); EndpointBuilder endpointBuilder = buildEndpoint(IPV4_0, MAC_0, CONNECTOR_0) .setL2Context(L2BD_ID); EndpointL3Builder endpointL3Builder = buildL3Endpoint(natAddr, IPV4_1, MAC_0, null) .setL2Context(L2BD_ID); endpointL3Builder.setTenant(tenant.getId()); Collection<EndpointL3> l3EndpointsWithNat = new HashSet<>(); l3EndpointsWithNat.add(endpointL3Builder.build()); when(ctx.getTenant(any(TenantId.class))).thenReturn(new IndexedTenant(tenant)); when(ctx.getEndpointManager()).thenReturn(endpointManager); when(ctx.getSwitchManager()).thenReturn(switchManager); when(ctx.getCurrentPolicy()).thenReturn(policyInfo); when(endpointManager.getEndpointNodeId(any(Endpoint.class))).thenReturn(NODE_ID); when(endpointManager.getL3EndpointsWithNat()).thenReturn(l3EndpointsWithNat); when(switchManager.getExternalPortNumbers(any(NodeId.class))).thenReturn(externalPorts); mapper.sync(endpointBuilder.build(), ofWriter); verify(ofWriter, times(3)).writeFlow(any(NodeId.class), any(Short.class), any(Flow.class)); }
@Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID)); ofWriter.writeFlow(nodeId, TABLE_ID, defaultFlow()); Collection<EndpointL3> natL3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); for (EndpointL3 natL3Ep : natL3Endpoints) { if (endpoint.getL2Context().equals(natL3Ep.getL2Context()) && endpoint.getMacAddress().equals(natL3Ep.getMacAddress())) { IpAddress natIpAddress = natL3Ep.getAugmentation(NatAddress.class).getNatAddress(); Subnet natIpSubnet = resolveSubnetForIpv4Address(ctx.getTenant(natL3Ep.getTenant()), Preconditions.checkNotNull(natIpAddress.getIpv4Address(), "Endpoint {} does not have IPv4 address in NatAddress augmentation.", natL3Ep.getKey())); if (natIpSubnet != null && natIpSubnet.getParent() != null) { L2FloodDomain natEpl2Fd = ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(natIpSubnet.getParent().getValue())); if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) { Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId(); ofWriter.writeFlow(nodeId, TABLE_ID, buildPushVlanFlow(natIpAddress.getIpv4Address(), vlanId, 222)); } } } } Subnet sub = ctx.getTenant(endpoint.getTenant()).resolveSubnet(new SubnetId(endpoint.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(endpoint.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(sub.getParent().getValue())); if (l2Fd == null) { return; } Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); EndpointFwdCtxOrdinals endpointOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (segmentation == null || endpointOrdinals == null) { return; } Integer vlanId = segmentation.getSegmentationId(); for (Flow flow : buildPushVlanFlow(nodeId, endpointOrdinals.getFdId(), vlanId, 220)) { ofWriter.writeFlow(nodeId, TABLE_ID, flow); } }
ExternalMapper extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID)); ofWriter.writeFlow(nodeId, TABLE_ID, defaultFlow()); Collection<EndpointL3> natL3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); for (EndpointL3 natL3Ep : natL3Endpoints) { if (endpoint.getL2Context().equals(natL3Ep.getL2Context()) && endpoint.getMacAddress().equals(natL3Ep.getMacAddress())) { IpAddress natIpAddress = natL3Ep.getAugmentation(NatAddress.class).getNatAddress(); Subnet natIpSubnet = resolveSubnetForIpv4Address(ctx.getTenant(natL3Ep.getTenant()), Preconditions.checkNotNull(natIpAddress.getIpv4Address(), "Endpoint {} does not have IPv4 address in NatAddress augmentation.", natL3Ep.getKey())); if (natIpSubnet != null && natIpSubnet.getParent() != null) { L2FloodDomain natEpl2Fd = ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(natIpSubnet.getParent().getValue())); if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) { Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId(); ofWriter.writeFlow(nodeId, TABLE_ID, buildPushVlanFlow(natIpAddress.getIpv4Address(), vlanId, 222)); } } } } Subnet sub = ctx.getTenant(endpoint.getTenant()).resolveSubnet(new SubnetId(endpoint.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(endpoint.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(sub.getParent().getValue())); if (l2Fd == null) { return; } Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); EndpointFwdCtxOrdinals endpointOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (segmentation == null || endpointOrdinals == null) { return; } Integer vlanId = segmentation.getSegmentationId(); for (Flow flow : buildPushVlanFlow(nodeId, endpointOrdinals.getFdId(), vlanId, 220)) { ofWriter.writeFlow(nodeId, TABLE_ID, flow); } } }
ExternalMapper extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID)); ofWriter.writeFlow(nodeId, TABLE_ID, defaultFlow()); Collection<EndpointL3> natL3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); for (EndpointL3 natL3Ep : natL3Endpoints) { if (endpoint.getL2Context().equals(natL3Ep.getL2Context()) && endpoint.getMacAddress().equals(natL3Ep.getMacAddress())) { IpAddress natIpAddress = natL3Ep.getAugmentation(NatAddress.class).getNatAddress(); Subnet natIpSubnet = resolveSubnetForIpv4Address(ctx.getTenant(natL3Ep.getTenant()), Preconditions.checkNotNull(natIpAddress.getIpv4Address(), "Endpoint {} does not have IPv4 address in NatAddress augmentation.", natL3Ep.getKey())); if (natIpSubnet != null && natIpSubnet.getParent() != null) { L2FloodDomain natEpl2Fd = ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(natIpSubnet.getParent().getValue())); if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) { Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId(); ofWriter.writeFlow(nodeId, TABLE_ID, buildPushVlanFlow(natIpAddress.getIpv4Address(), vlanId, 222)); } } } } Subnet sub = ctx.getTenant(endpoint.getTenant()).resolveSubnet(new SubnetId(endpoint.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(endpoint.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(sub.getParent().getValue())); if (l2Fd == null) { return; } Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); EndpointFwdCtxOrdinals endpointOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (segmentation == null || endpointOrdinals == null) { return; } Integer vlanId = segmentation.getSegmentationId(); for (Flow flow : buildPushVlanFlow(nodeId, endpointOrdinals.getFdId(), vlanId, 220)) { ofWriter.writeFlow(nodeId, TABLE_ID, flow); } } ExternalMapper(OfContext ctx, short tableId); }
ExternalMapper extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID)); ofWriter.writeFlow(nodeId, TABLE_ID, defaultFlow()); Collection<EndpointL3> natL3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); for (EndpointL3 natL3Ep : natL3Endpoints) { if (endpoint.getL2Context().equals(natL3Ep.getL2Context()) && endpoint.getMacAddress().equals(natL3Ep.getMacAddress())) { IpAddress natIpAddress = natL3Ep.getAugmentation(NatAddress.class).getNatAddress(); Subnet natIpSubnet = resolveSubnetForIpv4Address(ctx.getTenant(natL3Ep.getTenant()), Preconditions.checkNotNull(natIpAddress.getIpv4Address(), "Endpoint {} does not have IPv4 address in NatAddress augmentation.", natL3Ep.getKey())); if (natIpSubnet != null && natIpSubnet.getParent() != null) { L2FloodDomain natEpl2Fd = ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(natIpSubnet.getParent().getValue())); if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) { Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId(); ofWriter.writeFlow(nodeId, TABLE_ID, buildPushVlanFlow(natIpAddress.getIpv4Address(), vlanId, 222)); } } } } Subnet sub = ctx.getTenant(endpoint.getTenant()).resolveSubnet(new SubnetId(endpoint.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(endpoint.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(sub.getParent().getValue())); if (l2Fd == null) { return; } Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); EndpointFwdCtxOrdinals endpointOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (segmentation == null || endpointOrdinals == null) { return; } Integer vlanId = segmentation.getSegmentationId(); for (Flow flow : buildPushVlanFlow(nodeId, endpointOrdinals.getFdId(), vlanId, 220)) { ofWriter.writeFlow(nodeId, TABLE_ID, flow); } } ExternalMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); static Subnet resolveSubnetForIpv4Address(IndexedTenant t, Ipv4Address ipv4Addr); }
ExternalMapper extends FlowTable { @Override public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception { NodeId nodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint); ofWriter.writeFlow(nodeId, TABLE_ID, dropFlow(Integer.valueOf(1), null, TABLE_ID)); ofWriter.writeFlow(nodeId, TABLE_ID, defaultFlow()); Collection<EndpointL3> natL3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat(); for (EndpointL3 natL3Ep : natL3Endpoints) { if (endpoint.getL2Context().equals(natL3Ep.getL2Context()) && endpoint.getMacAddress().equals(natL3Ep.getMacAddress())) { IpAddress natIpAddress = natL3Ep.getAugmentation(NatAddress.class).getNatAddress(); Subnet natIpSubnet = resolveSubnetForIpv4Address(ctx.getTenant(natL3Ep.getTenant()), Preconditions.checkNotNull(natIpAddress.getIpv4Address(), "Endpoint {} does not have IPv4 address in NatAddress augmentation.", natL3Ep.getKey())); if (natIpSubnet != null && natIpSubnet.getParent() != null) { L2FloodDomain natEpl2Fd = ctx.getTenant(natL3Ep.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(natIpSubnet.getParent().getValue())); if (natEpl2Fd != null && natEpl2Fd.getAugmentation(Segmentation.class) != null) { Integer vlanId = natEpl2Fd.getAugmentation(Segmentation.class).getSegmentationId(); ofWriter.writeFlow(nodeId, TABLE_ID, buildPushVlanFlow(natIpAddress.getIpv4Address(), vlanId, 222)); } } } } Subnet sub = ctx.getTenant(endpoint.getTenant()).resolveSubnet(new SubnetId(endpoint.getNetworkContainment())); L2FloodDomain l2Fd = ctx.getTenant(endpoint.getTenant()).resolveL2FloodDomain(new L2FloodDomainId(sub.getParent().getValue())); if (l2Fd == null) { return; } Segmentation segmentation = l2Fd.getAugmentation(Segmentation.class); EndpointFwdCtxOrdinals endpointOrdinals = OrdinalFactory.getEndpointFwdCtxOrdinals(ctx, endpoint); if (segmentation == null || endpointOrdinals == null) { return; } Integer vlanId = segmentation.getSegmentationId(); for (Flow flow : buildPushVlanFlow(nodeId, endpointOrdinals.getFdId(), vlanId, 220)) { ofWriter.writeFlow(nodeId, TABLE_ID, flow); } } ExternalMapper(OfContext ctx, short tableId); @Override short getTableId(); @Override void sync(Endpoint endpoint, OfWriter ofWriter); static Subnet resolveSubnetForIpv4Address(IndexedTenant t, Ipv4Address ipv4Addr); static short TABLE_ID; }