*/
package org.opendaylight.ovsdb.southbound;
+import static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableBiMap;
+import com.google.common.net.InetAddresses;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import org.opendaylight.ovsdb.lib.OvsdbClient;
-import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo;
+import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
import org.opendaylight.ovsdb.lib.notation.UUID;
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
import org.opendaylight.ovsdb.schema.openvswitch.Controller;
+import org.opendaylight.ovsdb.schema.openvswitch.Manager;
+import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
+import org.opendaylight.ovsdb.schema.openvswitch.Qos;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeSystem;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentationBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.QosTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableBiMap;
-
public class SouthboundMapper {
private static final Logger LOG = LoggerFactory.getLogger(SouthboundMapper.class);
-
- public static Node createNode(OvsdbClient client) {
- NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setNodeId(createNodeId(client.getConnectionInfo()));
- nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, createOvsdbAugmentation(client));
- return nodeBuilder.build();
- }
- public static Node createNode(OvsdbClientKey key) {
- NodeBuilder nodeBuilder = new NodeBuilder();
- nodeBuilder.setNodeId(createNodeId(key.getIp(),key.getPort()));
- nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, createOvsdbAugmentation(key));
- return nodeBuilder.build();
- }
-
- public static OvsdbNodeAugmentation createOvsdbAugmentation(OvsdbClient client) {
- return createOvsdbAugmentation(new OvsdbClientKey(client));
- }
-
- public static OvsdbNodeAugmentation createOvsdbAugmentation(OvsdbClientKey key) {
- OvsdbNodeAugmentationBuilder ovsdbNodeBuilder = new OvsdbNodeAugmentationBuilder();
- ovsdbNodeBuilder.setIp(key.getIp());
- ovsdbNodeBuilder.setPort(key.getPort());
- return ovsdbNodeBuilder.build();
- }
+ private static final String N_CONNECTIONS_STR = "n_connections";
public static IpAddress createIpAddress(InetAddress address) {
IpAddress ip = null;
}
public static IpAddress createIpAddress(Inet4Address address) {
- Ipv4Address ipv4 = new Ipv4Address(address.getHostAddress());
- return new IpAddress(ipv4);
+ return IetfInetUtil.INSTANCE.ipAddressFor(address);
}
public static IpAddress createIpAddress(Inet6Address address) {
return new IpAddress(ipv6);
}
- public static InstanceIdentifier<Node> createInstanceIdentifier(OvsdbClient client) {
- return createInstanceIdentifier(createIpAddress(client.getConnectionInfo().getRemoteAddress()),
- new PortNumber(client.getConnectionInfo().getRemotePort()));
+ public static InstanceIdentifier<Topology> createTopologyInstanceIdentifier() {
+ return InstanceIdentifier
+ .create(NetworkTopology.class)
+ .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
}
- public static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
- InstanceIdentifier<Node> nodePath = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class,new NodeKey(nodeId));
- return nodePath;
+ public static InstanceIdentifier<OvsdbBridgeAugmentation>
+ createBridgeInstanceIdentifier(OvsdbConnectionInstance client, String bridgeName) {
+ return createInstanceIdentifier(client, bridgeName).augmentation(OvsdbBridgeAugmentation.class);
}
- public static InstanceIdentifier<Node> createInstanceIdentifier(OvsdbClientKey key,OvsdbBridgeName bridgeName) {
- return createInstanceIdentifier(createManagedNodeId(key, bridgeName));
+ public static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
+ return createTopologyInstanceIdentifier()
+ .child(Node.class,new NodeKey(nodeId));
}
- public static InstanceIdentifier<Node> createInstanceIdentifier(OvsdbClientKey key,Bridge bridge) {
- String managedNodePathString = bridge
- .getExternalIdsColumn()
- .getData()
- .get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
- InstanceIdentifier<Node> managedNodePath = null;
- if (managedNodePathString != null) {
- managedNodePath = (InstanceIdentifier<Node>) SouthboundUtil
- .deserializeInstanceIdentifier(managedNodePathString);
+ @SuppressWarnings("unchecked")
+ public static InstanceIdentifier<Node> createInstanceIdentifier(OvsdbConnectionInstance client,Bridge bridge) {
+ InstanceIdentifier<Node> iid;
+ if (bridge.getExternalIdsColumn() != null
+ && bridge.getExternalIdsColumn().getData() != null
+ && bridge.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
+ String iidString = bridge.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
+ iid = (InstanceIdentifier<Node>) SouthboundUtil.deserializeInstanceIdentifier(iidString);
+ } else {
+ iid = createInstanceIdentifier(client, bridge.getName());
}
- if (managedNodePath == null) {
- managedNodePath = SouthboundMapper.createInstanceIdentifier(key,new OvsdbBridgeName(bridge.getName()));
+ return iid;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static InstanceIdentifier<Node> createInstanceIdentifier(
+ OvsdbConnectionInstance client, Controller controller, String bridgeName) {
+ InstanceIdentifier<Node> iid;
+ if (controller.getExternalIdsColumn() != null
+ && controller.getExternalIdsColumn().getData() != null
+ && controller.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
+ String iidString = controller.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
+ iid = (InstanceIdentifier<Node>) SouthboundUtil.deserializeInstanceIdentifier(iidString);
+ } else {
+ iid = createInstanceIdentifier(client, bridgeName);
}
- return managedNodePath;
- }
-
- public static NodeId createManagedNodeId(InstanceIdentifier<Node> iid) {
- NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class);
- return nodeKey.getNodeId();
- }
-
- public static InstanceIdentifier<Node> createInstanceIdentifier(OvsdbClientKey key) {
- return createInstanceIdentifier(key.getIp(), key.getPort());
+ return iid;
}
- public static InstanceIdentifier<Node> createInstanceIdentifier(IpAddress ip, PortNumber port) {
- InstanceIdentifier<Node> path = InstanceIdentifier
- .create(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
- .child(Node.class,createNodeKey(ip,port));
- LOG.debug("Created ovsdb path: {}",path);
- return path;
- }
-
- public static NodeKey createNodeKey(IpAddress ip, PortNumber port) {
- return new NodeKey(createNodeId(ip,port));
- }
+ public static InstanceIdentifier<Node> createInstanceIdentifier(
+ OvsdbConnectionInstance client, String bridgeName) {
+ String nodeString = client.getNodeKey().getNodeId().getValue()
+ + "/bridge/" + bridgeName;
+ NodeId nodeId = new NodeId(new Uri(nodeString));
+ return createInstanceIdentifier(nodeId);
- public static NodeId createNodeId(OvsdbConnectionInfo connectionInfo) {
- return createNodeId(createIpAddress(connectionInfo.getRemoteAddress()),
- new PortNumber(connectionInfo.getRemotePort()));
}
- public static NodeId createManagedNodeId(OvsdbConnectionInfo connectionInfo, OvsdbBridgeName bridgeName) {
- return createManagedNodeId(createIpAddress(connectionInfo.getRemoteAddress()),
- new PortNumber(connectionInfo.getRemotePort()),
- bridgeName);
- }
-
- public static NodeId createManagedNodeId(OvsdbClientKey key, OvsdbBridgeName bridgeName) {
- return createManagedNodeId(key.getIp(),key.getPort(),bridgeName);
- }
-
- public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) {
- return new NodeId(createNodeId(ip,port).getValue()
- + "/" + SouthboundConstants.BRIDGE_URI_PREFIX + "/" + bridgeName.getValue());
- }
-
- public static NodeId createNodeId(IpAddress ip, PortNumber port) {
- String uriString = SouthboundConstants.OVSDB_URI_PREFIX + "://"
- + new String(ip.getValue()) + ":" + port.getValue();
- Uri uri = new Uri(uriString);
- NodeId nodeId = new NodeId(uri);
- return nodeId;
+ public static NodeId createManagedNodeId(InstanceIdentifier<Node> iid) {
+ NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class);
+ return nodeKey.getNodeId();
}
public static InetAddress createInetAddress(IpAddress ip) throws UnknownHostException {
if (ip.getIpv4Address() != null) {
- return InetAddress.getByName(ip.getIpv4Address().getValue());
+ return InetAddresses.forString(ip.getIpv4Address().getValue());
} else if (ip.getIpv6Address() != null) {
return InetAddress.getByName(ip.getIpv6Address().getValue());
} else {
}
}
+ public static DatapathId createDatapathId(String dpid) {
+ Preconditions.checkNotNull(dpid);
+ DatapathId datapath;
+ if (dpid.matches("^[0-9a-fA-F]{16}")) {
+ Splitter splitter = Splitter.fixedLength(2);
+ Joiner joiner = Joiner.on(":");
+ datapath = new DatapathId(joiner.join(splitter.split(dpid)));
+ } else {
+ datapath = new DatapathId(dpid);
+ }
+ return datapath;
+ }
+
public static String createDatapathType(OvsdbBridgeAugmentation mdsalbridge) {
- String datapathtype = new String(SouthboundConstants.DATAPATH_TYPE_MAP.get(DatapathTypeSystem.class));
+ String datapathtype = SouthboundConstants.DATAPATH_TYPE_MAP.get(DatapathTypeSystem.class);
- if (mdsalbridge.getDatapathType() != null) {
- if (SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType()) != null) {
- datapathtype = SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType());
- } else {
- throw new IllegalArgumentException("Unknown datapath type "
- + SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType()));
+ if (mdsalbridge.getDatapathType() != null && !mdsalbridge.getDatapathType().equals(DatapathTypeBase.class)) {
+ datapathtype = SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType());
+ if (datapathtype == null) {
+ throw new IllegalArgumentException("Unknown datapath type " + mdsalbridge.getDatapathType().getName());
}
}
return datapathtype;
}
}
- public static DatapathId createDatapathId(String dpid) {
- Preconditions.checkNotNull(dpid);
- DatapathId datapath;
- if (dpid.matches("^[0-9a-fA-F]{16}")) {
- Splitter splitter = Splitter.fixedLength(2);
- Joiner joiner = Joiner.on(":");
- datapath = new DatapathId(joiner.join(splitter.split(dpid)));
- } else {
- datapath = new DatapathId(dpid);
- }
- return datapath;
- }
-
public static Set<String> createOvsdbBridgeProtocols(OvsdbBridgeAugmentation ovsdbBridgeNode) {
- Set<String> protocols = new HashSet<String>();
+ Set<String> protocols = new HashSet<>();
if (ovsdbBridgeNode.getProtocolEntry() != null && ovsdbBridgeNode.getProtocolEntry().size() > 0) {
for (ProtocolEntry protocol : ovsdbBridgeNode.getProtocolEntry()) {
if (SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol()) != null) {
}
public static List<ProtocolEntry> createMdsalProtocols(Bridge bridge) {
- Set<String> protocols = bridge.getProtocolsColumn().getData();
- List<ProtocolEntry> protocolList = new ArrayList<ProtocolEntry>();
+ Set<String> protocols = null;
+ try {
+ protocols = bridge.getProtocolsColumn().getData();
+ } catch (SchemaVersionMismatchException e) {
+ schemaMismatchLog("protocols", "Bridge", e);
+ }
+ List<ProtocolEntry> protocolList = new ArrayList<>();
if (protocols != null && protocols.size() > 0) {
ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
for (String protocol : protocols) {
if (protocol != null && mapper.get(protocol) != null) {
- protocolList.add(new ProtocolEntryBuilder().
- setProtocol((Class<? extends OvsdbBridgeProtocolBase>) mapper.get(protocol)).build());
+ protocolList.add(new ProtocolEntryBuilder().setProtocol(mapper.get(protocol)).build());
}
}
}
return protocolList;
}
- public static List<ControllerEntry> createControllerEntries(Bridge bridge,Map<UUID,
- Controller> updatedControllerRows) {
- LOG.debug("Bridge: {}, updatedControllerRows: {}",bridge,updatedControllerRows);
- Set<UUID> controllerUUIDs = bridge.getControllerColumn().getData();
- List<ControllerEntry> controllerEntries = new ArrayList<ControllerEntry>();
- for (UUID controllerUUID : controllerUUIDs ) {
- Controller controller = updatedControllerRows.get(controllerUUID);
- if (controller != null && controller.getTargetColumn() != null
- && controller.getTargetColumn() != null) {
- String targetString = controller.getTargetColumn().getData();
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid uuid =
- new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
+ /**
+ * Create the {@link ControllerEntry} list given an OVSDB {@link Bridge}
+ * and {@link Controller} rows.
+ *
+ * @param bridge the {@link Bridge} to update
+ * @param updatedControllerRows the list of {@link Controller} controllers with updates
+ * @return list of {@link ControllerEntry} entries
+ */
+ public static List<ControllerEntry> createControllerEntries(Bridge bridge,
+ Map<UUID, Controller> updatedControllerRows) {
+
+ LOG.debug("createControllerEntries Bridge: {}\n, updatedControllerRows: {}",
+ bridge, updatedControllerRows);
+ final Set<UUID> controllerUuids = bridge.getControllerColumn().getData();
+ final List<ControllerEntry> controllerEntries = new ArrayList<>();
+ for (UUID controllerUuid : controllerUuids ) {
+ final Controller controller = updatedControllerRows.get(controllerUuid);
+ addControllerEntries(controllerEntries, controller);
+ }
+ LOG.debug("controllerEntries: {}", controllerEntries);
+ return controllerEntries;
+ }
+
+ /**
+ * Create the {@link ControllerEntry} list given an MDSAL {@link Node} bridge
+ * and {@link Controller} rows.
+ *
+ * @param bridgeNode the {@link Node} to update
+ * @param updatedControllerRows the list of {@link Controller} controllers with updates
+ * @return list of {@link ControllerEntry} entries
+ */
+ public static List<ControllerEntry> createControllerEntries(Node bridgeNode,
+ Map<UUID, Controller> updatedControllerRows) {
+
+ LOG.debug("createControllerEntries Bridge 2: {}\n, updatedControllerRows: {}",
+ bridgeNode, updatedControllerRows);
+ final List<ControllerEntry> controllerEntriesCreated = new ArrayList<>();
+ final OvsdbBridgeAugmentation ovsdbBridgeAugmentation =
+ bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
+ if (ovsdbBridgeAugmentation == null) {
+ return controllerEntriesCreated;
+ }
+
+ final List<ControllerEntry> controllerEntries = ovsdbBridgeAugmentation.getControllerEntry();
+ if (controllerEntries != null) {
+ for (ControllerEntry controllerEntry : controllerEntries) {
+ final Controller controller = updatedControllerRows.get(
+ new UUID(controllerEntry.getControllerUuid().getValue()));
+ addControllerEntries(controllerEntriesCreated, controller);
+ }
+ }
+ LOG.debug("controllerEntries: {}", controllerEntriesCreated);
+ return controllerEntriesCreated;
+ }
+
+ /**
+ * Add the OVSDB {@link Controller} updates to the MDSAL {@link ControllerEntry} list.
+ *
+ * @param controllerEntries the list of {@link ControllerEntry} to update
+ * @param controller the updated OVSDB {@link Controller}
+ */
+ public static void addControllerEntries(List<ControllerEntry> controllerEntries,
+ final Controller controller) {
+
+ if (controller != null && controller.getTargetColumn() != null) {
+ final String targetString = controller.getTargetColumn().getData();
+ final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid uuid =
+ new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
.ietf.yang.types.rev130715.Uuid(controller.getUuid().toString());
- controllerEntries.add(new ControllerEntryBuilder()
+
+ controllerEntries.add(new ControllerEntryBuilder()
.setTarget(new Uri(targetString))
+ .setIsConnected(controller.getIsConnectedColumn().getData())
.setControllerUuid(uuid).build());
- }
}
- return controllerEntries;
}
public static Map<UUID, Controller> createOvsdbController(OvsdbBridgeAugmentation omn,DatabaseSchema dbSchema) {
List<ControllerEntry> controllerEntries = omn.getControllerEntry();
- Map<UUID,Controller> controllerMap = new HashMap<UUID,Controller>();
+ Map<UUID,Controller> controllerMap = new HashMap<>();
if (controllerEntries != null && !controllerEntries.isEmpty()) {
- int index = 0;
for (ControllerEntry controllerEntry : controllerEntries) {
- String controllerNamedUUID = "Controller_" + getRandomUUID();
+ String controllerNamedUuid = "Controller_" + getRandomUuid();
Controller controller = TyperUtils.getTypedRowWrapper(dbSchema, Controller.class);
controller.setTarget(controllerEntry.getTarget().getValue());
- controllerMap.put(new UUID(controllerNamedUUID), controller);
+ controllerMap.put(new UUID(controllerNamedUuid), controller);
}
}
return controllerMap;
}
- public static String getRandomUUID() {
+ public static String getRandomUuid() {
return "Random_" + java.util.UUID.randomUUID().toString().replace("-", "");
}
+
+ public static ConnectionInfo createConnectionInfo(OvsdbClient client) {
+ ConnectionInfoBuilder connectionInfoBuilder = new ConnectionInfoBuilder();
+ connectionInfoBuilder.setRemoteIp(createIpAddress(client.getConnectionInfo().getRemoteAddress()));
+ connectionInfoBuilder.setRemotePort(new PortNumber(client.getConnectionInfo().getRemotePort()));
+ connectionInfoBuilder.setLocalIp(createIpAddress(client.getConnectionInfo().getLocalAddress()));
+ connectionInfoBuilder.setLocalPort(new PortNumber(client.getConnectionInfo().getLocalPort()));
+ return connectionInfoBuilder.build();
+ }
+
+ public static ConnectionInfo suppressLocalIpPort(ConnectionInfo connectionInfo) {
+ ConnectionInfoBuilder connectionInfoBuilder = new ConnectionInfoBuilder();
+ connectionInfoBuilder.setRemoteIp(connectionInfo.getRemoteIp());
+ connectionInfoBuilder.setRemotePort(connectionInfo.getRemotePort());
+ return connectionInfoBuilder.build();
+ }
+
+ /**
+ * Create the {@link ManagerEntry} list given an OVSDB {@link OpenVSwitch}
+ * and {@link Manager} rows.
+ *
+ * @param ovsdbNode the {@link OpenVSwitch} to update
+ * @param updatedManagerRows the list of {@link Manager} managers with updates
+ * @return list of {@link ManagerEntry} entries
+ */
+ public static List<ManagerEntry> createManagerEntries(OpenVSwitch ovsdbNode,
+ Map<UUID, Manager> updatedManagerRows) {
+
+ LOG.debug("createManagerEntries OpenVSwitch: {}\n, updatedManagerRows: {}",
+ ovsdbNode, updatedManagerRows);
+ final Set<UUID> managerUuids = ovsdbNode.getManagerOptionsColumn().getData();
+ final List<ManagerEntry> managerEntries = new ArrayList<>();
+ for (UUID managerUuid : managerUuids) {
+ final Manager manager = updatedManagerRows.get(managerUuid);
+ addManagerEntries(managerEntries, manager);
+ }
+ LOG.debug("managerEntries: {}", managerEntries);
+ return managerEntries;
+ }
+
+ /**
+ * Create the {@link ManagerEntry} list given an MDSAL {@link Node} ovsdbNode
+ * and {@link Manager} rows.
+ *
+ * @param ovsdbNode the {@link Node} to update
+ * @param updatedManagerRows the list of {@link Manager} managers with updates
+ * @return list of {@link ManagerEntry} entries
+ */
+ public static List<ManagerEntry> createManagerEntries(Node ovsdbNode,
+ Map<Uri, Manager> updatedManagerRows) {
+
+ LOG.debug("createManagerEntries based on OVSDB Node: {}\n, updatedManagerRows: {}",
+ ovsdbNode, updatedManagerRows);
+ final List<ManagerEntry> managerEntriesCreated = new ArrayList<>();
+ final OvsdbNodeAugmentation ovsdbNodeAugmentation =
+ ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
+ if (ovsdbNodeAugmentation == null) {
+ return managerEntriesCreated;
+ }
+
+ final List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
+ if (managerEntries != null) {
+ for (ManagerEntry managerEntry : managerEntries) {
+ final Manager manager = updatedManagerRows.get(managerEntry.getTarget());
+ addManagerEntries(managerEntriesCreated, manager);
+ }
+ }
+ LOG.debug("managerEntries: {}", managerEntriesCreated);
+ return managerEntriesCreated;
+ }
+
+ /**
+ * Add the OVSDB {@link Manager} updates to the MDSAL {@link ManagerEntry} list.
+ *
+ * @param managerEntries the list of {@link ManagerEntry} to update
+ * @param manager the updated OVSDB {@link Manager}
+ */
+ public static void addManagerEntries(List<ManagerEntry> managerEntries,
+ final Manager manager) {
+
+ if (manager != null && manager.getTargetColumn() != null) {
+ long numberOfConnections = 0;
+ final String targetString = manager.getTargetColumn().getData();
+
+ final Map<String, String> statusAttributeMap = manager.getStatusColumn().getData();
+ if (statusAttributeMap.containsKey(N_CONNECTIONS_STR)) {
+ String numberOfConnectionValueStr = statusAttributeMap.get(N_CONNECTIONS_STR);
+ numberOfConnections = Integer.parseInt(numberOfConnectionValueStr);
+ } else {
+ final boolean isConnected = manager.getIsConnectedColumn().getData();
+ if (isConnected) {
+ numberOfConnections = 1;
+ }
+ }
+ managerEntries.add(new ManagerEntryBuilder()
+ .setTarget(new Uri(targetString))
+ .setNumberOfConnections(numberOfConnections)
+ .setConnected(manager.getIsConnectedColumn().getData()).build());
+ }
+ }
+
+ /**
+ * Return the MD-SAL QoS type class corresponding to the QoS type {@link Qos}.
+ *
+ * @param type the QoS type to match {@link String}
+ * @return class matching the input QoS type {@link QosTypeBase}
+ */
+ public static Class<? extends QosTypeBase> createQosType(String type) {
+ Preconditions.checkNotNull(type);
+ if (type.isEmpty()) {
+ LOG.info("QoS type not supplied");
+ return QosTypeBase.class;
+ } else {
+ ImmutableBiMap<String, Class<? extends QosTypeBase>> mapper =
+ SouthboundConstants.QOS_TYPE_MAP.inverse();
+ if (mapper.get(type) == null) {
+ LOG.info("QoS type not found in model: {}", type);
+ return QosTypeBase.class;
+ } else {
+ return mapper.get(type);
+ }
+ }
+ }
+
+ public static String createQosType(Class<? extends QosTypeBase> qosTypeClass) {
+ String qosType = SouthboundConstants.QOS_TYPE_MAP.get(QosTypeBase.class);
+
+ if (qosTypeClass != null && !qosTypeClass.equals(QosTypeBase.class)) {
+ qosType = SouthboundConstants.QOS_TYPE_MAP.get(qosTypeClass);
+ if (qosType == null) {
+ throw new IllegalArgumentException("Unknown QoS type" + qosTypeClass.getName());
+ }
+ }
+ return qosType;
+ }
+
+
+ public static InstanceIdentifier<Node> getInstanceIdentifier(OpenVSwitch ovs) {
+ if (ovs.getExternalIdsColumn() != null
+ && ovs.getExternalIdsColumn().getData() != null
+ && ovs.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
+ String iidString = ovs.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
+ return (InstanceIdentifier<Node>) SouthboundUtil.deserializeInstanceIdentifier(iidString);
+ } else {
+ String nodeString = SouthboundConstants.OVSDB_URI_PREFIX + "://" + SouthboundConstants.UUID + "/"
+ + ovs.getUuid().toString();
+ NodeId nodeId = new NodeId(new Uri(nodeString));
+ NodeKey nodeKey = new NodeKey(nodeId);
+ return InstanceIdentifier.builder(NetworkTopology.class)
+ .child(Topology.class,new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
+ .child(Node.class,nodeKey)
+ .build();
+ }
+ }
}