PacketDispatcher { public void floodPacket(String nodeId, byte[] payload, NodeConnectorRef origIngress, NodeConnectorRef controllerNodeConnector) { List<NodeConnectorRef> nodeConnectors = inventoryReader.getSwitchNodeConnectors().get(nodeId); if (nodeConnectors == null) { refreshInventoryReader(); nodeConnectors = inventoryReader.getSwitchNodeConnectors().get(nodeId); if (nodeConnectors == null) { LOG.info("Cannot flood packets, as inventory doesn't have any node connectors for node {}", nodeId); return; } } for (NodeConnectorRef ncRef : nodeConnectors) { String ncId = ncRef.getValue().firstIdentifierOf(NodeConnector.class) .firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue(); if (!ncId.equals(origIngress.getValue().firstIdentifierOf(NodeConnector.class) .firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue())) { sendPacketOut(payload, origIngress, ncRef); } } }  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);  }
@Test public void testFloodPacket() throws Exception { List<NodeConnectorRef> nodeConnectors = new ArrayList<>(); InstanceIdentifier<NodeConnector> ncInsId1 = InstanceIdentifier.builder(Nodes.class).child(Node.class) .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("1"))).build(); InstanceIdentifier<NodeConnector> ncInsId2 = InstanceIdentifier.builder(Nodes.class).child(Node.class) .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.floodPacket("", null, new NodeConnectorRef(ncInsId2), new NodeConnectorRef(InstanceIdentifier.create(NodeConnector.class))); verify(inventoryReader, times(0)).setRefreshData(true); verify(inventoryReader, times(0)).readInventory(); verify(packetProcessingService, times(2)).transmitPacket(any(TransmitPacketInput.class)); }
@Test public void testFloodPacket_NullList() throws Exception { HashMap<String, List<NodeConnectorRef>> switchNodeConnectors = Mockito.mock(HashMap.class); when(switchNodeConnectors.get(any(String.class))).thenReturn(null); when(inventoryReader.getSwitchNodeConnectors()).thenReturn(switchNodeConnectors); packetDispatcher.floodPacket("", null, new NodeConnectorRef(InstanceIdentifier.create(NodeConnector.class)), new NodeConnectorRef(InstanceIdentifier.create(NodeConnector.class))); verify(inventoryReader, times(1)).setRefreshData(true); verify(inventoryReader, times(1)).readInventory(); verify(packetProcessingService, times(0)).transmitPacket(any(TransmitPacketInput.class)); }