@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testRemoveTunnelsOfOverlayConfig_TunnelTypeEqualsFalse() throws Exception { AbstractTunnelType tunnelType = mock(AbstractTunnelType.class); ReadWriteTransaction transaction = mock(ReadWriteTransaction.class); when(dataBroker.newReadWriteTransaction()).thenReturn(transaction); CheckedFuture<Optional<OfOverlayNodeConfig>, ReadFailedException> checkedFuture = mock(CheckedFuture.class); when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))) .thenReturn(checkedFuture); Optional<OfOverlayNodeConfig> optionalOverlayConfig = mock(Optional.class); when(checkedFuture.checkedGet()).thenReturn(optionalOverlayConfig); when(optionalOverlayConfig.isPresent()).thenReturn(true); OfOverlayNodeConfig overlayConfig = mock(OfOverlayNodeConfig.class); when(optionalOverlayConfig.get()).thenReturn(overlayConfig); Tunnel overlayTunnel = mock(Tunnel.class); when(overlayConfig.getTunnel()).thenReturn(Collections.singletonList(overlayTunnel)); when(tunnelType.getTunnelType()).thenReturn((Class) TunnelTypeVxlan.class); when(overlayTunnel.getTunnelType()).thenReturn(null); InventoryHelper.removeTunnelsOfOverlayConfig(nodeIdString, Collections.singletonList(tunnelType), dataBroker); verify(writeTransaction, never()).submit(); }
public static void removeTunnelsOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> tunnels, DataBroker dataBroker) { if (nodeIdString == null) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } List<Tunnel> existingTunnels = new ArrayList<>(); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); if (ofConfig != null) { existingTunnels = ofConfig.getTunnel(); } Set<Tunnel> tunnelsToRemove = new HashSet<>(); for (AbstractTunnelType tunnelType : tunnels) { for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelsToRemove.add(currentTun); } } } if (existingTunnels.removeAll(tunnelsToRemove)) { ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction(); for (Tunnel tunnel : tunnelsToRemove) { InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId(nodeIdString))) .augmentation(OfOverlayNodeConfig.class) .child(Tunnel.class, tunnel.getKey()) .build(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid); LOG.trace("Removing tunnel: {} from node {}",tunnel, nodeIdString); } submitToDs(writeTx); } }
InventoryHelper { public static void removeTunnelsOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> tunnels, DataBroker dataBroker) { if (nodeIdString == null) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } List<Tunnel> existingTunnels = new ArrayList<>(); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); if (ofConfig != null) { existingTunnels = ofConfig.getTunnel(); } Set<Tunnel> tunnelsToRemove = new HashSet<>(); for (AbstractTunnelType tunnelType : tunnels) { for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelsToRemove.add(currentTun); } } } if (existingTunnels.removeAll(tunnelsToRemove)) { ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction(); for (Tunnel tunnel : tunnelsToRemove) { InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId(nodeIdString))) .augmentation(OfOverlayNodeConfig.class) .child(Tunnel.class, tunnel.getKey()) .build(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid); LOG.trace("Removing tunnel: {} from node {}",tunnel, nodeIdString); } submitToDs(writeTx); } } }
InventoryHelper { public static void removeTunnelsOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> tunnels, DataBroker dataBroker) { if (nodeIdString == null) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } List<Tunnel> existingTunnels = new ArrayList<>(); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); if (ofConfig != null) { existingTunnels = ofConfig.getTunnel(); } Set<Tunnel> tunnelsToRemove = new HashSet<>(); for (AbstractTunnelType tunnelType : tunnels) { for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelsToRemove.add(currentTun); } } } if (existingTunnels.removeAll(tunnelsToRemove)) { ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction(); for (Tunnel tunnel : tunnelsToRemove) { InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId(nodeIdString))) .augmentation(OfOverlayNodeConfig.class) .child(Tunnel.class, tunnel.getKey()) .build(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid); LOG.trace("Removing tunnel: {} from node {}",tunnel, nodeIdString); } submitToDs(writeTx); } }  }
InventoryHelper { public static void removeTunnelsOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> tunnels, DataBroker dataBroker) { if (nodeIdString == null) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } List<Tunnel> existingTunnels = new ArrayList<>(); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); if (ofConfig != null) { existingTunnels = ofConfig.getTunnel(); } Set<Tunnel> tunnelsToRemove = new HashSet<>(); for (AbstractTunnelType tunnelType : tunnels) { for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelsToRemove.add(currentTun); } } } if (existingTunnels.removeAll(tunnelsToRemove)) { ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction(); for (Tunnel tunnel : tunnelsToRemove) { InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId(nodeIdString))) .augmentation(OfOverlayNodeConfig.class) .child(Tunnel.class, tunnel.getKey()) .build(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid); LOG.trace("Removing tunnel: {} from node {}",tunnel, nodeIdString); } submitToDs(writeTx); } }  static Long getLongFromDpid(String dpid); static String getInventoryNodeIdString(OvsdbBridgeAugmentation ovsdbBridge,
            InstanceIdentifier<OvsdbTerminationPointAugmentation> ovsdbTpIid, DataBroker dataBroker); static String getInventoryNodeConnectorIdString(String inventoryNodeId,
            OvsdbTerminationPointAugmentation ovsdbTp, InstanceIdentifier<OvsdbTerminationPointAugmentation> tpIid,
            DataBroker dataBroker); static boolean checkOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> requiredTunnelTypes,
            DataBroker dataBroker); static InstanceIdentifier<ExternalInterfaces> addOfOverlayExternalPort(NodeId nodeId, NodeConnectorId ncId,
        DataBroker dataBroker); static OfOverlayNodeConfig getOfOverlayConfig(String nodeIdString, DataBroker dataBroker); static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString,
            AbstractTunnelType tunnelType, DataBroker dataBroker); static void removeTunnelsOfOverlayConfig(String nodeIdString,
                                                    List<AbstractTunnelType> tunnels,
                                                    DataBroker dataBroker); }
InventoryHelper { public static void removeTunnelsOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> tunnels, DataBroker dataBroker) { if (nodeIdString == null) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } List<Tunnel> existingTunnels = new ArrayList<>(); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); if (ofConfig != null) { existingTunnels = ofConfig.getTunnel(); } Set<Tunnel> tunnelsToRemove = new HashSet<>(); for (AbstractTunnelType tunnelType : tunnels) { for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelsToRemove.add(currentTun); } } } if (existingTunnels.removeAll(tunnelsToRemove)) { ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction(); for (Tunnel tunnel : tunnelsToRemove) { InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(new NodeId(nodeIdString))) .augmentation(OfOverlayNodeConfig.class) .child(Tunnel.class, tunnel.getKey()) .build(); writeTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid); LOG.trace("Removing tunnel: {} from node {}",tunnel, nodeIdString); } submitToDs(writeTx); } }  static Long getLongFromDpid(String dpid); static String getInventoryNodeIdString(OvsdbBridgeAugmentation ovsdbBridge,
            InstanceIdentifier<OvsdbTerminationPointAugmentation> ovsdbTpIid, DataBroker dataBroker); static String getInventoryNodeConnectorIdString(String inventoryNodeId,
            OvsdbTerminationPointAugmentation ovsdbTp, InstanceIdentifier<OvsdbTerminationPointAugmentation> tpIid,
            DataBroker dataBroker); static boolean checkOfOverlayConfig(String nodeIdString, List<AbstractTunnelType> requiredTunnelTypes,
            DataBroker dataBroker); static InstanceIdentifier<ExternalInterfaces> addOfOverlayExternalPort(NodeId nodeId, NodeConnectorId ncId,
        DataBroker dataBroker); static OfOverlayNodeConfig getOfOverlayConfig(String nodeIdString, DataBroker dataBroker); static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString,
            AbstractTunnelType tunnelType, DataBroker dataBroker); static void removeTunnelsOfOverlayConfig(String nodeIdString,
                                                    List<AbstractTunnelType> tunnels,
                                                    DataBroker dataBroker);  }