@Test public void testDispatchPacket_toFloodPacket() throws Exception { InstanceIdentifier<NodeConnector> ncInsId1 = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId("1"))) .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("1"))).build(); NodeConnectorRef ncRef1 = new NodeConnectorRef(ncInsId1); HashMap<String, NodeConnectorRef> controllerSwitchConnectors = Mockito.mock(HashMap.class); when(controllerSwitchConnectors.get(any(String.class))).thenReturn(ncRef1); when(inventoryReader.getControllerSwitchConnectors()).thenReturn(controllerSwitchConnectors); when(inventoryReader.getNodeConnector(any(InstanceIdentifier.class), any(MacAddress.class))).thenReturn(null); List<NodeConnectorRef> nodeConnectors = new ArrayList<>(); InstanceIdentifier<NodeConnector> ncInsId2 = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId("2"))) .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("2"))).build(); nodeConnectors.add(new NodeConnectorRef(ncInsId1)); nodeConnectors.add(new NodeConnectorRef(ncInsId1)); nodeConnectors.add(new NodeConnectorRef(ncInsId2)); HashMap<String, List<NodeConnectorRef>> switchNodeConnectors = Mockito.mock(HashMap.class); when(switchNodeConnectors.get(any(String.class))).thenReturn(nodeConnectors); when(inventoryReader.getSwitchNodeConnectors()).thenReturn(switchNodeConnectors); packetDispatcher.dispatchPacket(null, new NodeConnectorRef(ncInsId2), null, null); verify(inventoryReader, times(1)).readInventory(); verify(inventoryReader, times(0)).setRefreshData(true); verify(packetProcessingService, times(2)).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);  }