FlowUtils implements AutoCloseable { public void handleArp(PacketReceived packetReceived, NodeConnectorRef ingress) { byte[] payload = packetReceived.getPayload(); Ethernet ethernet = new Ethernet(); try { ethernet.deserialize(payload, 0, NetUtils.NUM_BITS_IN_A_BYTE * payload.length); } catch ( PacketException exception ) { LOG.error("Failed to decode the received packet to ethernet packet."); return; } ARP arp = new ARP(); try { arp.deserialize(ethernet.getRawPayload(), 0, NetUtils.NUM_BITS_IN_A_BYTE * ethernet.getRawPayload().length); } catch ( PacketException exception ) { LOG.error("Failed to decode the raw payload of ethernet packet to arp packet."); return; } ImmutableTriple<VirtualNetworkId, VirtualNodeId, VirtualPortId> mappingValueForExternalPhysicalPort = arpHandlerHelper.getMappingValueForExternalPhysicalPort(ingress); VirtualNetworkId virtualNetworkId = mappingValueForExternalPhysicalPort.getLeft(); VirtualNodeId ingressVirtualNodeId = mappingValueForExternalPhysicalPort.getMiddle(); VirtualPortId ingressVirtualPortId = mappingValueForExternalPhysicalPort.getRight(); IpAddress srcIpAddress = convertByteArray4ToIpAddress(arp.getSenderProtocolAddress()); IpAddress dstIpAddress = convertByteArray4ToIpAddress(arp.getTargetProtocolAddress()); VirtualNetworkHelper virtualNetworkHelper = virtualNetworkHelpers.get(virtualNetworkId); VirtualNode ingressVirtualNode = virtualNetworkHelper.getVirtualNode(ingressVirtualNodeId); VirtualArp virtualArp; switch ( ingressVirtualNode.getNodeType() ) { case Vswitch: virtualArp = virtualNetworkHelper.getVirtualArp(srcIpAddress); if ( null == virtualArp ) { virtualArp = new VirtualArpBuilder() .setIpAddress(srcIpAddress) .setMacAddress(convertByteArray6ToMacAddress(arp.getSenderHardwareAddress())) .setNodeId(ingressVirtualNodeId) .setPortId(ingressVirtualPortId) .build(); virtualNetworkHelper.addVirtualArp(virtualArp); UserId userId = new UserId(virtualNetworkId.getValue()); Map<VirtualNodeId, Map.Entry<VirtualPort, VirtualLink>> connectedVirtualRouters = virtualNetworkHelper.getConnectedVirtualRouters(ingressVirtualNodeId); if ( null != connectedVirtualRouters && !connectedVirtualRouters.isEmpty() ) { VirtualLink virtualLink = virtualNetworkHelper.getVirtualLink( connectedVirtualRouters.keySet().iterator().next(), ingressVirtualNodeId); VnPnMappingResult vnPnMappingResult = getVnPnMappingResult( userVnPnMappings.get(userId).getVnPnMappingResult(), new VirtualResourceEntityId(virtualLink.getLinkId().getValue())); PhysicalPathId physicalPathId = new PhysicalPathId( vnPnMappingResult.getPhysicalResourceEntityId().getValue()); PhysicalPath physicalPath = physicalNetworkHelper.getPhysicalPath(physicalPathId); configArpTableEntry(userId, virtualArp, physicalPath); } PhysicalNodeId ingressPhysicalNodeId = convertNodeConnectorRefToPhysicalNodeId(ingress); PhysicalPortId ingressPhysicalPortId = convertNodeConnectorRefToPhysicalPortId(ingress); configMacTableEntry(userId, virtualArp.getMacAddress(), ingressPhysicalNodeId, ingressPhysicalPortId); Map<VirtualNodeId, Map.Entry<VirtualPort, VirtualLink>> connectedVirtualSwitches = virtualNetworkHelper.getConnectedVirtualSwitches(ingressVirtualNodeId); if ( null != connectedVirtualSwitches && !connectedVirtualSwitches.isEmpty() ) { List<VnPnMappingResult> vnPnMappingResults = userVnPnMappings.get(userId).getVnPnMappingResult(); VirtualLink virtualLink; VnPnMappingResult vnPnMappingResult; PhysicalPathId physicalPathId; PhysicalPath physicalPath; for ( VirtualNodeId virtualNodeId : connectedVirtualSwitches.keySet() ) { virtualLink = virtualNetworkHelper.getVirtualLink(virtualNodeId, ingressVirtualNodeId); vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualLink.getLinkId().getValue())); physicalPathId = new PhysicalPathId( vnPnMappingResult.getPhysicalResourceEntityId().getValue()); physicalPath = physicalNetworkHelper.getPhysicalPath(physicalPathId); configMacTableEntry(userId, virtualArp.getMacAddress(), physicalPath); } } } if ( ARP.REQUEST == arp.getOpCode() ) { IpAddress gatewayIpAddress = getGatewayIpAddress(virtualNetworkId, ingressVirtualNode); if ( dstIpAddress.equals(gatewayIpAddress) ) { MacAddress gatewayMacAddress = getGatewayMacAddress(virtualNetworkId, ingressVirtualNode); byte[] targetProtocolAddress = arp.getTargetProtocolAddress(); arp.setTargetHardwareAddress(arp.getSenderHardwareAddress()); arp.setTargetProtocolAddress(arp.getSenderProtocolAddress()); arp.setSenderHardwareAddress(convertMacAddressToByteArray6(gatewayMacAddress)); arp.setSenderProtocolAddress(targetProtocolAddress); arp.setOpCode(ARP.REPLY); ethernet.setSourceMACAddress(arp.getSenderHardwareAddress()); ethernet.setDestinationMACAddress(arp.getTargetHardwareAddress()); sendPacketOut(createArpPacket(ethernet, arp), ingress, ingress); break; } virtualArp = virtualNetworkHelper.getVirtualArp(dstIpAddress); if ( null != virtualArp ) { byte[] targetProtocolAddress = arp.getTargetProtocolAddress(); arp.setTargetHardwareAddress(arp.getSenderHardwareAddress()); arp.setTargetProtocolAddress(arp.getSenderProtocolAddress()); arp.setSenderHardwareAddress(convertMacAddressToByteArray6(virtualArp.getMacAddress())); arp.setSenderProtocolAddress(targetProtocolAddress); arp.setOpCode(ARP.REPLY); ethernet.setSourceMACAddress(arp.getSenderHardwareAddress()); ethernet.setDestinationMACAddress(arp.getTargetHardwareAddress()); sendPacketOut(createArpPacket(ethernet, arp), ingress, ingress); break; } Map<VirtualNodeId, Map.Entry<VirtualPort, VirtualLink>> connectedVirtualSwitches = virtualNetworkHelper.getConnectedVirtualSwitches(ingressVirtualNodeId); if ( null != connectedVirtualSwitches && !connectedVirtualSwitches.isEmpty() ) { UserId userId = new UserId(virtualNetworkId.getValue()); UserVnPnMapping userVnPnMapping = userVnPnMappings.get(userId); List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VirtualPort layer2ExternalVirtualPort; VnPnMappingResult vnPnMappingResult; PhysicalNodeId physicalNodeId; PhysicalPortId physicalPortId; for ( VirtualNodeId virtualNodeId : connectedVirtualSwitches.keySet() ) { layer2ExternalVirtualPort = virtualNetworkHelper.getLayer2ExternalVirtualPort(virtualNodeId); if ( null != layer2ExternalVirtualPort ) { vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(layer2ExternalVirtualPort.getPortId().getValue())); physicalNodeId = new PhysicalNodeId( vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); physicalPortId = new PhysicalPortId( vnPnMappingResult.getPhysicalResourceEntityId().getValue()); sendPacketOut(payload, ingress, createNodeConnectorRef(physicalNodeId, physicalPortId)); } } } } else { virtualArp = virtualNetworkHelper.getVirtualArp(dstIpAddress); if ( null != virtualArp ) { UserId userId = new UserId(virtualNetworkId.getValue()); UserVnPnMapping userVnPnMapping = userVnPnMappings.get(userId); List<VnPnMappingResult> vnPnMappingResults = userVnPnMapping.getVnPnMappingResult(); VnPnMappingResult vnPnMappingResult = getVnPnMappingResult(vnPnMappingResults, new VirtualResourceEntityId(virtualArp.getPortId().getValue())); PhysicalNodeId physicalNodeId = new PhysicalNodeId( vnPnMappingResult.getParentPhysicalResourceEntityId().getValue()); PhysicalPortId physicalPortId = new PhysicalPortId( vnPnMappingResult.getPhysicalResourceEntityId().getValue()); sendPacketOut(payload, ingress, createNodeConnectorRef(physicalNodeId, physicalPortId)); } } break; case Vrouter: VirtualPort ingressVirtualPort = virtualNetworkHelper .getVirtualPort(ingressVirtualNodeId, ingressVirtualPortId); if ( virtualNetworkHelper.isLayer2ExternalVirtualPort(ingressVirtualPort) ) { virtualArp = virtualNetworkHelper.getVirtualArp(srcIpAddress); if ( null == virtualArp ) { virtualArp = new VirtualArpBuilder() .setIpAddress(srcIpAddress) .setMacAddress(convertByteArray6ToMacAddress(arp.getSenderHardwareAddress())) .setNodeId(ingressVirtualNodeId) .setPortId(ingressVirtualPortId) .build(); virtualNetworkHelper.addVirtualArp(virtualArp); UserId userId = new UserId(virtualNetworkId.getValue()); PhysicalNodeId ingressPhysicalNodeId = convertNodeConnectorRefToPhysicalNodeId(ingress); PhysicalPortId ingressPhysicalPortId = convertNodeConnectorRefToPhysicalPortId(ingress); configArpTableEntry(userId, virtualArp, ingressPhysicalNodeId, ingressPhysicalPortId); } if ( ARP.REQUEST == arp.getOpCode() ) { IpAddress gatewayIpAddress = getGatewayIpAddress(virtualNetworkId, ingressVirtualNode); if ( dstIpAddress.equals(gatewayIpAddress) ) { MacAddress gatewayMacAddress = getGatewayMacAddress(virtualNetworkId, ingressVirtualNode); byte[] targetProtocolAddress = arp.getTargetProtocolAddress(); arp.setTargetHardwareAddress(arp.getSenderHardwareAddress()); arp.setTargetProtocolAddress(arp.getSenderProtocolAddress()); arp.setSenderHardwareAddress(convertMacAddressToByteArray6(gatewayMacAddress)); arp.setSenderProtocolAddress(targetProtocolAddress); arp.setOpCode(ARP.REPLY); ethernet.setSourceMACAddress(arp.getSenderHardwareAddress()); ethernet.setDestinationMACAddress(arp.getTargetHardwareAddress()); sendPacketOut(createArpPacket(ethernet, arp), ingress, ingress); } } } break; default: break; } return; } FlowUtils(DataBroker dataBroker,
                     PacketProcessingService packetProcessingService,
                     PhyConfigLoader phyConfigLoader); void init(List<PhysicalNode> physicalNodes); void handleArp(PacketReceived packetReceived, NodeConnectorRef ingress); @Override void close(); void assignMPLSLabelForPPath(PhysicalPath physicalPath,
                  List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink> physicalLinksList);  }
@Test public void testHandleArp() throws Exception { }