@Test public void createLocalL3RoutedFlow_sameSubnetIdAndExceptionCaught() { NodeConnectorId connectorId = new NodeConnectorId(OPENFLOW + CONNECTOR_0.getValue()); OfOverlayContextBuilder ofOverlayContextBuilder = new OfOverlayContextBuilder(); ofOverlayContextBuilder.setNodeConnectorId(new NodeConnectorId(CONNECTOR_1)); EndpointBuilder endpointBuilder = buildEndpoint(IPV6_1, MAC_1, connectorId); endpointBuilder.addAugmentation(OfOverlayContext.class, ofOverlayContextBuilder.build()); endpointBuilder.setNetworkContainment(SUBNET_0); endpointBuilder.setTenant(getTestIndexedTenant().getTenant().getId()); Endpoint endpoint = endpointBuilder.build(); SubnetBuilder localSubnetBuilder = new SubnetBuilder(); localSubnetBuilder.setId(SUBNET_0); localSubnetBuilder.setParent(L2FD_ID); Subnet localSubnet = localSubnetBuilder.build(); SubnetBuilder destSubnetBuilder = new SubnetBuilder(); destSubnetBuilder.setId(SUBNET_1); destSubnetBuilder.setParent(L2FD_ID); Subnet destSubnet = destSubnetBuilder.build(); flows.createLocalL3RoutedFlow(tableId, 80, endpoint, null, localSubnet, destSubnet, ofWriter); verifyZeroInteractions(ofWriter); }
void createLocalL3RoutedFlow(short goToTable, int priority, Endpoint endpoint, L3Address l3Address, Subnet localSubnet, Subnet destSubnet, OfWriter ofWriter) { NodeConnectorId connectorId = endpoint.getAugmentation(OfOverlayContext.class).getNodeConnectorId(); L3Context l3Context = utils.getL3ContextForSubnet(utils.getIndexedTenant(endpoint.getTenant()), localSubnet); if (l3Context == null) { return; } MacAddress matcherMac = utils.routerPortMac(l3Context, localSubnet.getVirtualRouterIp(), endpoint.getTenant()); MacAddress epDestMac = endpoint.getMacAddress(); if (matcherMac == null || epDestMac == null) { return; } MacAddress destSubnetGatewayMac = utils.routerPortMac(l3Context, destSubnet.getVirtualRouterIp(), endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpoint); if (localSubnet.getId().getValue().equals(destSubnet.getId().getValue())) { matcherMac = epDestMac; } Action setNextHopAction; try { setNextHopAction = nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(getOfPortNum(connectorId))); } catch (NumberFormatException ex) { LOG.warn("Could not parse port number {}", connectorId, ex); return; } List<Action> l3ApplyActions = new ArrayList<>(); l3ApplyActions.add(setDlDstAction(epDestMac)); l3ApplyActions.add(decNwTtlAction()); if (!(matcherMac.getValue().equals(epDestMac.getValue()))) { l3ApplyActions.add(setDlSrcAction(destSubnetGatewayMac)); } List<Action> applyActions = new ArrayList<>(); applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(ordinals.getEpgId()))); applyActions.add(nxLoadRegAction(NxmNxReg3.class, BigInteger.valueOf(ordinals.getCgId()))); applyActions.add(setNextHopAction); applyActions.addAll(l3ApplyActions); int order = 0; Instruction applyActionsIns = new InstructionBuilder().setOrder(order++) .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()]))) .build(); Instruction gotoTable = new InstructionBuilder().setOrder(order) .setInstruction(gotoTableIns(goToTable)) .build(); ArrayList<Instruction> l3instructions = new ArrayList<>(); l3instructions.add(applyActionsIns); l3instructions.add(gotoTable); Layer3Match l3Match; Long etherType; String ikey; if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv4Address() != null) { ikey = l3Address.getIpAddress().getIpv4Address().getValue() + "/32"; etherType = IPv4; l3Match = new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(ikey)).build(); } else if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv6Address() != null) { ikey = l3Address.getIpAddress().getIpv6Address().getValue() + "/128"; etherType = IPv6; l3Match = new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(ikey)).build(); } else { LOG.error("Endpoint has IPAddress that is not recognised as either IPv4 or IPv6.", l3Address.toString()); return; } MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, matcherMac, etherType)) .setLayer3Match(l3Match); addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) ordinals.getL3Id())); Match match = matchBuilder.build(); FlowId flowid = FlowIdUtils.newFlowId(tableId, "localL3", match); FlowBuilder flowBuilder = base(tableId).setId(flowid) .setPriority(priority) .setMatch(match) .setInstructions(new InstructionsBuilder().setInstruction(l3instructions).build()); ofWriter.writeFlow(nodeId, tableId, flowBuilder.build()); }
DestinationMapperFlows { void createLocalL3RoutedFlow(short goToTable, int priority, Endpoint endpoint, L3Address l3Address, Subnet localSubnet, Subnet destSubnet, OfWriter ofWriter) { NodeConnectorId connectorId = endpoint.getAugmentation(OfOverlayContext.class).getNodeConnectorId(); L3Context l3Context = utils.getL3ContextForSubnet(utils.getIndexedTenant(endpoint.getTenant()), localSubnet); if (l3Context == null) { return; } MacAddress matcherMac = utils.routerPortMac(l3Context, localSubnet.getVirtualRouterIp(), endpoint.getTenant()); MacAddress epDestMac = endpoint.getMacAddress(); if (matcherMac == null || epDestMac == null) { return; } MacAddress destSubnetGatewayMac = utils.routerPortMac(l3Context, destSubnet.getVirtualRouterIp(), endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpoint); if (localSubnet.getId().getValue().equals(destSubnet.getId().getValue())) { matcherMac = epDestMac; } Action setNextHopAction; try { setNextHopAction = nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(getOfPortNum(connectorId))); } catch (NumberFormatException ex) { LOG.warn("Could not parse port number {}", connectorId, ex); return; } List<Action> l3ApplyActions = new ArrayList<>(); l3ApplyActions.add(setDlDstAction(epDestMac)); l3ApplyActions.add(decNwTtlAction()); if (!(matcherMac.getValue().equals(epDestMac.getValue()))) { l3ApplyActions.add(setDlSrcAction(destSubnetGatewayMac)); } List<Action> applyActions = new ArrayList<>(); applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(ordinals.getEpgId()))); applyActions.add(nxLoadRegAction(NxmNxReg3.class, BigInteger.valueOf(ordinals.getCgId()))); applyActions.add(setNextHopAction); applyActions.addAll(l3ApplyActions); int order = 0; Instruction applyActionsIns = new InstructionBuilder().setOrder(order++) .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()]))) .build(); Instruction gotoTable = new InstructionBuilder().setOrder(order) .setInstruction(gotoTableIns(goToTable)) .build(); ArrayList<Instruction> l3instructions = new ArrayList<>(); l3instructions.add(applyActionsIns); l3instructions.add(gotoTable); Layer3Match l3Match; Long etherType; String ikey; if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv4Address() != null) { ikey = l3Address.getIpAddress().getIpv4Address().getValue() + "/32"; etherType = IPv4; l3Match = new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(ikey)).build(); } else if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv6Address() != null) { ikey = l3Address.getIpAddress().getIpv6Address().getValue() + "/128"; etherType = IPv6; l3Match = new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(ikey)).build(); } else { LOG.error("Endpoint has IPAddress that is not recognised as either IPv4 or IPv6.", l3Address.toString()); return; } MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, matcherMac, etherType)) .setLayer3Match(l3Match); addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) ordinals.getL3Id())); Match match = matchBuilder.build(); FlowId flowid = FlowIdUtils.newFlowId(tableId, "localL3", match); FlowBuilder flowBuilder = base(tableId).setId(flowid) .setPriority(priority) .setMatch(match) .setInstructions(new InstructionsBuilder().setInstruction(l3instructions).build()); ofWriter.writeFlow(nodeId, tableId, flowBuilder.build()); } }
DestinationMapperFlows { void createLocalL3RoutedFlow(short goToTable, int priority, Endpoint endpoint, L3Address l3Address, Subnet localSubnet, Subnet destSubnet, OfWriter ofWriter) { NodeConnectorId connectorId = endpoint.getAugmentation(OfOverlayContext.class).getNodeConnectorId(); L3Context l3Context = utils.getL3ContextForSubnet(utils.getIndexedTenant(endpoint.getTenant()), localSubnet); if (l3Context == null) { return; } MacAddress matcherMac = utils.routerPortMac(l3Context, localSubnet.getVirtualRouterIp(), endpoint.getTenant()); MacAddress epDestMac = endpoint.getMacAddress(); if (matcherMac == null || epDestMac == null) { return; } MacAddress destSubnetGatewayMac = utils.routerPortMac(l3Context, destSubnet.getVirtualRouterIp(), endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpoint); if (localSubnet.getId().getValue().equals(destSubnet.getId().getValue())) { matcherMac = epDestMac; } Action setNextHopAction; try { setNextHopAction = nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(getOfPortNum(connectorId))); } catch (NumberFormatException ex) { LOG.warn("Could not parse port number {}", connectorId, ex); return; } List<Action> l3ApplyActions = new ArrayList<>(); l3ApplyActions.add(setDlDstAction(epDestMac)); l3ApplyActions.add(decNwTtlAction()); if (!(matcherMac.getValue().equals(epDestMac.getValue()))) { l3ApplyActions.add(setDlSrcAction(destSubnetGatewayMac)); } List<Action> applyActions = new ArrayList<>(); applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(ordinals.getEpgId()))); applyActions.add(nxLoadRegAction(NxmNxReg3.class, BigInteger.valueOf(ordinals.getCgId()))); applyActions.add(setNextHopAction); applyActions.addAll(l3ApplyActions); int order = 0; Instruction applyActionsIns = new InstructionBuilder().setOrder(order++) .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()]))) .build(); Instruction gotoTable = new InstructionBuilder().setOrder(order) .setInstruction(gotoTableIns(goToTable)) .build(); ArrayList<Instruction> l3instructions = new ArrayList<>(); l3instructions.add(applyActionsIns); l3instructions.add(gotoTable); Layer3Match l3Match; Long etherType; String ikey; if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv4Address() != null) { ikey = l3Address.getIpAddress().getIpv4Address().getValue() + "/32"; etherType = IPv4; l3Match = new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(ikey)).build(); } else if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv6Address() != null) { ikey = l3Address.getIpAddress().getIpv6Address().getValue() + "/128"; etherType = IPv6; l3Match = new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(ikey)).build(); } else { LOG.error("Endpoint has IPAddress that is not recognised as either IPv4 or IPv6.", l3Address.toString()); return; } MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, matcherMac, etherType)) .setLayer3Match(l3Match); addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) ordinals.getL3Id())); Match match = matchBuilder.build(); FlowId flowid = FlowIdUtils.newFlowId(tableId, "localL3", match); FlowBuilder flowBuilder = base(tableId).setId(flowid) .setPriority(priority) .setMatch(match) .setInstructions(new InstructionsBuilder().setInstruction(l3instructions).build()); ofWriter.writeFlow(nodeId, tableId, flowBuilder.build()); } DestinationMapperFlows(DestinationMapperUtils utils, NodeId nodeId, short tableId); }
DestinationMapperFlows { void createLocalL3RoutedFlow(short goToTable, int priority, Endpoint endpoint, L3Address l3Address, Subnet localSubnet, Subnet destSubnet, OfWriter ofWriter) { NodeConnectorId connectorId = endpoint.getAugmentation(OfOverlayContext.class).getNodeConnectorId(); L3Context l3Context = utils.getL3ContextForSubnet(utils.getIndexedTenant(endpoint.getTenant()), localSubnet); if (l3Context == null) { return; } MacAddress matcherMac = utils.routerPortMac(l3Context, localSubnet.getVirtualRouterIp(), endpoint.getTenant()); MacAddress epDestMac = endpoint.getMacAddress(); if (matcherMac == null || epDestMac == null) { return; } MacAddress destSubnetGatewayMac = utils.routerPortMac(l3Context, destSubnet.getVirtualRouterIp(), endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpoint); if (localSubnet.getId().getValue().equals(destSubnet.getId().getValue())) { matcherMac = epDestMac; } Action setNextHopAction; try { setNextHopAction = nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(getOfPortNum(connectorId))); } catch (NumberFormatException ex) { LOG.warn("Could not parse port number {}", connectorId, ex); return; } List<Action> l3ApplyActions = new ArrayList<>(); l3ApplyActions.add(setDlDstAction(epDestMac)); l3ApplyActions.add(decNwTtlAction()); if (!(matcherMac.getValue().equals(epDestMac.getValue()))) { l3ApplyActions.add(setDlSrcAction(destSubnetGatewayMac)); } List<Action> applyActions = new ArrayList<>(); applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(ordinals.getEpgId()))); applyActions.add(nxLoadRegAction(NxmNxReg3.class, BigInteger.valueOf(ordinals.getCgId()))); applyActions.add(setNextHopAction); applyActions.addAll(l3ApplyActions); int order = 0; Instruction applyActionsIns = new InstructionBuilder().setOrder(order++) .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()]))) .build(); Instruction gotoTable = new InstructionBuilder().setOrder(order) .setInstruction(gotoTableIns(goToTable)) .build(); ArrayList<Instruction> l3instructions = new ArrayList<>(); l3instructions.add(applyActionsIns); l3instructions.add(gotoTable); Layer3Match l3Match; Long etherType; String ikey; if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv4Address() != null) { ikey = l3Address.getIpAddress().getIpv4Address().getValue() + "/32"; etherType = IPv4; l3Match = new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(ikey)).build(); } else if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv6Address() != null) { ikey = l3Address.getIpAddress().getIpv6Address().getValue() + "/128"; etherType = IPv6; l3Match = new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(ikey)).build(); } else { LOG.error("Endpoint has IPAddress that is not recognised as either IPv4 or IPv6.", l3Address.toString()); return; } MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, matcherMac, etherType)) .setLayer3Match(l3Match); addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) ordinals.getL3Id())); Match match = matchBuilder.build(); FlowId flowid = FlowIdUtils.newFlowId(tableId, "localL3", match); FlowBuilder flowBuilder = base(tableId).setId(flowid) .setPriority(priority) .setMatch(match) .setInstructions(new InstructionsBuilder().setInstruction(l3instructions).build()); ofWriter.writeFlow(nodeId, tableId, flowBuilder.build()); } DestinationMapperFlows(DestinationMapperUtils utils, NodeId nodeId, short tableId);  }
DestinationMapperFlows { void createLocalL3RoutedFlow(short goToTable, int priority, Endpoint endpoint, L3Address l3Address, Subnet localSubnet, Subnet destSubnet, OfWriter ofWriter) { NodeConnectorId connectorId = endpoint.getAugmentation(OfOverlayContext.class).getNodeConnectorId(); L3Context l3Context = utils.getL3ContextForSubnet(utils.getIndexedTenant(endpoint.getTenant()), localSubnet); if (l3Context == null) { return; } MacAddress matcherMac = utils.routerPortMac(l3Context, localSubnet.getVirtualRouterIp(), endpoint.getTenant()); MacAddress epDestMac = endpoint.getMacAddress(); if (matcherMac == null || epDestMac == null) { return; } MacAddress destSubnetGatewayMac = utils.routerPortMac(l3Context, destSubnet.getVirtualRouterIp(), endpoint.getTenant()); OrdinalFactory.EndpointFwdCtxOrdinals ordinals = utils.getEndpointOrdinals(endpoint); if (localSubnet.getId().getValue().equals(destSubnet.getId().getValue())) { matcherMac = epDestMac; } Action setNextHopAction; try { setNextHopAction = nxLoadRegAction(NxmNxReg7.class, BigInteger.valueOf(getOfPortNum(connectorId))); } catch (NumberFormatException ex) { LOG.warn("Could not parse port number {}", connectorId, ex); return; } List<Action> l3ApplyActions = new ArrayList<>(); l3ApplyActions.add(setDlDstAction(epDestMac)); l3ApplyActions.add(decNwTtlAction()); if (!(matcherMac.getValue().equals(epDestMac.getValue()))) { l3ApplyActions.add(setDlSrcAction(destSubnetGatewayMac)); } List<Action> applyActions = new ArrayList<>(); applyActions.add(nxLoadRegAction(NxmNxReg2.class, BigInteger.valueOf(ordinals.getEpgId()))); applyActions.add(nxLoadRegAction(NxmNxReg3.class, BigInteger.valueOf(ordinals.getCgId()))); applyActions.add(setNextHopAction); applyActions.addAll(l3ApplyActions); int order = 0; Instruction applyActionsIns = new InstructionBuilder().setOrder(order++) .setInstruction(applyActionIns(applyActions.toArray(new Action[applyActions.size()]))) .build(); Instruction gotoTable = new InstructionBuilder().setOrder(order) .setInstruction(gotoTableIns(goToTable)) .build(); ArrayList<Instruction> l3instructions = new ArrayList<>(); l3instructions.add(applyActionsIns); l3instructions.add(gotoTable); Layer3Match l3Match; Long etherType; String ikey; if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv4Address() != null) { ikey = l3Address.getIpAddress().getIpv4Address().getValue() + "/32"; etherType = IPv4; l3Match = new Ipv4MatchBuilder().setIpv4Destination(new Ipv4Prefix(ikey)).build(); } else if (l3Address.getIpAddress() != null && l3Address.getIpAddress().getIpv6Address() != null) { ikey = l3Address.getIpAddress().getIpv6Address().getValue() + "/128"; etherType = IPv6; l3Match = new Ipv6MatchBuilder().setIpv6Destination(new Ipv6Prefix(ikey)).build(); } else { LOG.error("Endpoint has IPAddress that is not recognised as either IPv4 or IPv6.", l3Address.toString()); return; } MatchBuilder matchBuilder = new MatchBuilder().setEthernetMatch(ethernetMatch(null, matcherMac, etherType)) .setLayer3Match(l3Match); addNxRegMatch(matchBuilder, RegMatch.of(NxmNxReg6.class, (long) ordinals.getL3Id())); Match match = matchBuilder.build(); FlowId flowid = FlowIdUtils.newFlowId(tableId, "localL3", match); FlowBuilder flowBuilder = base(tableId).setId(flowid) .setPriority(priority) .setMatch(match) .setInstructions(new InstructionsBuilder().setInstruction(l3instructions).build()); ofWriter.writeFlow(nodeId, tableId, flowBuilder.build()); } DestinationMapperFlows(DestinationMapperUtils utils, NodeId nodeId, short tableId);   }