@Test public void testDispatchPacket_noDispatch() throws Exception { InstanceIdentifier<NodeConnector> ncInsId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId("1"))) .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("1"))).build(); HashMap<String, NodeConnectorRef> controllerSwitchConnectors = Mockito.mock(HashMap.class); when(controllerSwitchConnectors.get(any(String.class))).thenReturn(null); when(inventoryReader.getControllerSwitchConnectors()).thenReturn(controllerSwitchConnectors); packetDispatcher.dispatchPacket(null, new NodeConnectorRef(ncInsId), null, null); verify(inventoryReader, times(2)).readInventory(); verify(inventoryReader, times(1)).setRefreshData(true); verify(packetProcessingService, times(0)).transmitPacket(any(TransmitPacketInput.class)); }
public void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) { inventoryReader.readInventory(); String nodeId = ingress.getValue().firstIdentifierOf(Node.class).firstKeyOf(Node.class, NodeKey.class).getId() .getValue(); NodeConnectorRef srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); if (srcConnectorRef == null) { refreshInventoryReader(); srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); } NodeConnectorRef destNodeConnector = inventoryReader .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac); if (srcConnectorRef != null) { if (destNodeConnector != null) { sendPacketOut(payload, srcConnectorRef, destNodeConnector); } else { floodPacket(nodeId, payload, ingress, srcConnectorRef); } } else { LOG.info("Cannot send packet out or flood as controller node connector is not available for node {}.", nodeId); } }
PacketDispatcher { public void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) { inventoryReader.readInventory(); String nodeId = ingress.getValue().firstIdentifierOf(Node.class).firstKeyOf(Node.class, NodeKey.class).getId() .getValue(); NodeConnectorRef srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); if (srcConnectorRef == null) { refreshInventoryReader(); srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); } NodeConnectorRef destNodeConnector = inventoryReader .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac); if (srcConnectorRef != null) { if (destNodeConnector != null) { sendPacketOut(payload, srcConnectorRef, destNodeConnector); } else { floodPacket(nodeId, payload, ingress, srcConnectorRef); } } else { LOG.info("Cannot send packet out or flood as controller node connector is not available for node {}.", nodeId); } } }
PacketDispatcher { public void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) { inventoryReader.readInventory(); String nodeId = ingress.getValue().firstIdentifierOf(Node.class).firstKeyOf(Node.class, NodeKey.class).getId() .getValue(); NodeConnectorRef srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); if (srcConnectorRef == null) { refreshInventoryReader(); srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); } NodeConnectorRef destNodeConnector = inventoryReader .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac); if (srcConnectorRef != null) { if (destNodeConnector != null) { sendPacketOut(payload, srcConnectorRef, destNodeConnector); } else { floodPacket(nodeId, payload, ingress, srcConnectorRef); } } else { LOG.info("Cannot send packet out or flood as controller node connector is not available for node {}.", nodeId); } }  }
PacketDispatcher { public void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) { inventoryReader.readInventory(); String nodeId = ingress.getValue().firstIdentifierOf(Node.class).firstKeyOf(Node.class, NodeKey.class).getId() .getValue(); NodeConnectorRef srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); if (srcConnectorRef == null) { refreshInventoryReader(); srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); } NodeConnectorRef destNodeConnector = inventoryReader .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac); if (srcConnectorRef != null) { if (destNodeConnector != null) { sendPacketOut(payload, srcConnectorRef, destNodeConnector); } else { floodPacket(nodeId, payload, ingress, srcConnectorRef); } } else { LOG.info("Cannot send packet out or flood as controller node connector is not available for node {}.", nodeId); } }  void setPacketProcessingService(PacketProcessingService packetProcessingService); void setInventoryReader(InventoryReader inventoryReader); void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac); void floodPacket(String nodeId, byte[] payload, NodeConnectorRef origIngress,
            NodeConnectorRef controllerNodeConnector); void sendPacketOut(byte[] payload, NodeConnectorRef ingress, NodeConnectorRef egress); }
PacketDispatcher { public void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac) { inventoryReader.readInventory(); String nodeId = ingress.getValue().firstIdentifierOf(Node.class).firstKeyOf(Node.class, NodeKey.class).getId() .getValue(); NodeConnectorRef srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); if (srcConnectorRef == null) { refreshInventoryReader(); srcConnectorRef = inventoryReader.getControllerSwitchConnectors().get(nodeId); } NodeConnectorRef destNodeConnector = inventoryReader .getNodeConnector(ingress.getValue().firstIdentifierOf(Node.class), destMac); if (srcConnectorRef != null) { if (destNodeConnector != null) { sendPacketOut(payload, srcConnectorRef, destNodeConnector); } else { floodPacket(nodeId, payload, ingress, srcConnectorRef); } } else { LOG.info("Cannot send packet out or flood as controller node connector is not available for node {}.", nodeId); } }  void setPacketProcessingService(PacketProcessingService packetProcessingService); void setInventoryReader(InventoryReader inventoryReader); void dispatchPacket(byte[] payload, NodeConnectorRef ingress, MacAddress srcMac, MacAddress destMac); void floodPacket(String nodeId, byte[] payload, NodeConnectorRef origIngress,
            NodeConnectorRef controllerNodeConnector); void sendPacketOut(byte[] payload, NodeConnectorRef ingress, NodeConnectorRef egress);  }