@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testUpdateOfOverlayConfig() throws Exception { AbstractTunnelType tunnelType = mock(AbstractTunnelType.class); when(writeTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))) .thenReturn(nodeConfigFuture); when(nodeConfigOptional.isPresent()).thenReturn(true); OfOverlayNodeConfig overlayConfig = mock(OfOverlayNodeConfig.class); when(nodeConfigOptional.get()).thenReturn(overlayConfig); Tunnel tunnel = mock(Tunnel.class); when(overlayConfig.getTunnel()).thenReturn(Collections.singletonList(tunnel)); when(tunnelType.getTunnelType()).thenReturn((Class) TunnelTypeVxlan.class); when(tunnel.getTunnelType()).thenReturn((Class) TunnelTypeVxlan.class); when(tunnel.getKey()).thenReturn(mock(TunnelKey.class)); CheckedFuture<Void, TransactionCommitFailedException> submitFuture = mock(CheckedFuture.class); when(writeTransaction.submit()).thenReturn(submitFuture); IpAddress ip = mock(IpAddress.class); String nodeConnectorIdString = "nodeConnectorIdString"; InventoryHelper.updateOfOverlayConfig(ip, nodeIdString, nodeConnectorIdString, tunnelType, dataBroker); verify(writeTransaction).submit(); }
public static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString, AbstractTunnelType tunnelType, DataBroker dataBroker) { if ((ip == null) || (nodeIdString == null) || (nodeConnectorIdString == null)) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeConnectorIdString); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); OfOverlayNodeConfigBuilder ofOverlayNodeConfigBuilder; Set<Tunnel> existingTunnels = new HashSet<Tunnel>(); if (ofConfig != null) { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(ofConfig); if (ofConfig.getTunnel() != null) { existingTunnels.addAll(ofConfig.getTunnel()); } } else { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(); } boolean tunnelsUpdated = false; TunnelBuilder tunnelBuilder = new TunnelBuilder(); boolean tunnelFound = false; for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelFound = true; tunnelsUpdated = true; break; } } if (tunnelFound == false) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelsUpdated = true; } if (tunnelsUpdated == false) { return; } existingTunnels.add(tunnelBuilder.build()); if (!existingTunnels.isEmpty()) { ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<Tunnel>(existingTunnels)); } OfOverlayNodeConfig newConfig = ofOverlayNodeConfigBuilder.build(); if (addOfOverlayConfig(newConfig, new NodeId(nodeIdString), dataBroker)) { LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}", tunnelBuilder.build(), nodeIdString, nodeConnectorIdString); } else { LOG.error("updateOfOverlayConfig - could not write OfOverlayNodeConfig: {} to datastore.", newConfig); } }
InventoryHelper { public static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString, AbstractTunnelType tunnelType, DataBroker dataBroker) { if ((ip == null) || (nodeIdString == null) || (nodeConnectorIdString == null)) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeConnectorIdString); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); OfOverlayNodeConfigBuilder ofOverlayNodeConfigBuilder; Set<Tunnel> existingTunnels = new HashSet<Tunnel>(); if (ofConfig != null) { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(ofConfig); if (ofConfig.getTunnel() != null) { existingTunnels.addAll(ofConfig.getTunnel()); } } else { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(); } boolean tunnelsUpdated = false; TunnelBuilder tunnelBuilder = new TunnelBuilder(); boolean tunnelFound = false; for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelFound = true; tunnelsUpdated = true; break; } } if (tunnelFound == false) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelsUpdated = true; } if (tunnelsUpdated == false) { return; } existingTunnels.add(tunnelBuilder.build()); if (!existingTunnels.isEmpty()) { ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<Tunnel>(existingTunnels)); } OfOverlayNodeConfig newConfig = ofOverlayNodeConfigBuilder.build(); if (addOfOverlayConfig(newConfig, new NodeId(nodeIdString), dataBroker)) { LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}", tunnelBuilder.build(), nodeIdString, nodeConnectorIdString); } else { LOG.error("updateOfOverlayConfig - could not write OfOverlayNodeConfig: {} to datastore.", newConfig); } } }
InventoryHelper { public static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString, AbstractTunnelType tunnelType, DataBroker dataBroker) { if ((ip == null) || (nodeIdString == null) || (nodeConnectorIdString == null)) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeConnectorIdString); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); OfOverlayNodeConfigBuilder ofOverlayNodeConfigBuilder; Set<Tunnel> existingTunnels = new HashSet<Tunnel>(); if (ofConfig != null) { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(ofConfig); if (ofConfig.getTunnel() != null) { existingTunnels.addAll(ofConfig.getTunnel()); } } else { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(); } boolean tunnelsUpdated = false; TunnelBuilder tunnelBuilder = new TunnelBuilder(); boolean tunnelFound = false; for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelFound = true; tunnelsUpdated = true; break; } } if (tunnelFound == false) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelsUpdated = true; } if (tunnelsUpdated == false) { return; } existingTunnels.add(tunnelBuilder.build()); if (!existingTunnels.isEmpty()) { ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<Tunnel>(existingTunnels)); } OfOverlayNodeConfig newConfig = ofOverlayNodeConfigBuilder.build(); if (addOfOverlayConfig(newConfig, new NodeId(nodeIdString), dataBroker)) { LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}", tunnelBuilder.build(), nodeIdString, nodeConnectorIdString); } else { LOG.error("updateOfOverlayConfig - could not write OfOverlayNodeConfig: {} to datastore.", newConfig); } }  }
InventoryHelper { public static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString, AbstractTunnelType tunnelType, DataBroker dataBroker) { if ((ip == null) || (nodeIdString == null) || (nodeConnectorIdString == null)) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeConnectorIdString); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); OfOverlayNodeConfigBuilder ofOverlayNodeConfigBuilder; Set<Tunnel> existingTunnels = new HashSet<Tunnel>(); if (ofConfig != null) { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(ofConfig); if (ofConfig.getTunnel() != null) { existingTunnels.addAll(ofConfig.getTunnel()); } } else { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(); } boolean tunnelsUpdated = false; TunnelBuilder tunnelBuilder = new TunnelBuilder(); boolean tunnelFound = false; for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelFound = true; tunnelsUpdated = true; break; } } if (tunnelFound == false) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelsUpdated = true; } if (tunnelsUpdated == false) { return; } existingTunnels.add(tunnelBuilder.build()); if (!existingTunnels.isEmpty()) { ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<Tunnel>(existingTunnels)); } OfOverlayNodeConfig newConfig = ofOverlayNodeConfigBuilder.build(); if (addOfOverlayConfig(newConfig, new NodeId(nodeIdString), dataBroker)) { LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}", tunnelBuilder.build(), nodeIdString, nodeConnectorIdString); } else { LOG.error("updateOfOverlayConfig - could not write OfOverlayNodeConfig: {} to datastore.", newConfig); } }  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 updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString, AbstractTunnelType tunnelType, DataBroker dataBroker) { if ((ip == null) || (nodeIdString == null) || (nodeConnectorIdString == null)) { LOG.debug("Can't update OfOverlay: requisite information not present"); return; } NodeConnectorId nodeConnectorId = new NodeConnectorId(nodeConnectorIdString); OfOverlayNodeConfig ofConfig = getOfOverlayConfig(nodeIdString, dataBroker); OfOverlayNodeConfigBuilder ofOverlayNodeConfigBuilder; Set<Tunnel> existingTunnels = new HashSet<Tunnel>(); if (ofConfig != null) { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(ofConfig); if (ofConfig.getTunnel() != null) { existingTunnels.addAll(ofConfig.getTunnel()); } } else { ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(); } boolean tunnelsUpdated = false; TunnelBuilder tunnelBuilder = new TunnelBuilder(); boolean tunnelFound = false; for (Tunnel currentTun : existingTunnels) { if (tunnelType.getTunnelType().equals(currentTun.getTunnelType())) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelFound = true; tunnelsUpdated = true; break; } } if (tunnelFound == false) { tunnelBuilder.setIp(ip); tunnelBuilder.setPort(tunnelType.getPortNumber()); tunnelBuilder.setNodeConnectorId(nodeConnectorId); tunnelBuilder.setTunnelType(tunnelType.getTunnelType()); tunnelsUpdated = true; } if (tunnelsUpdated == false) { return; } existingTunnels.add(tunnelBuilder.build()); if (!existingTunnels.isEmpty()) { ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<Tunnel>(existingTunnels)); } OfOverlayNodeConfig newConfig = ofOverlayNodeConfigBuilder.build(); if (addOfOverlayConfig(newConfig, new NodeId(nodeIdString), dataBroker)) { LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}", tunnelBuilder.build(), nodeIdString, nodeConnectorIdString); } else { LOG.error("updateOfOverlayConfig - could not write OfOverlayNodeConfig: {} to datastore.", newConfig); } }  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);  }