ovsdb enable checkstyle on error
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / SouthboundMapper.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.ovsdb.southbound;
9
10 import static org.opendaylight.ovsdb.southbound.SouthboundUtil.schemaMismatchLog;
11
12 import com.google.common.base.Joiner;
13 import com.google.common.base.Preconditions;
14 import com.google.common.base.Splitter;
15 import com.google.common.collect.ImmutableBiMap;
16 import com.google.common.net.InetAddresses;
17 import java.net.Inet4Address;
18 import java.net.Inet6Address;
19 import java.net.InetAddress;
20 import java.net.UnknownHostException;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import org.opendaylight.ovsdb.lib.OvsdbClient;
28 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
29 import org.opendaylight.ovsdb.lib.notation.UUID;
30 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
31 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
32 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
33 import org.opendaylight.ovsdb.schema.openvswitch.Controller;
34 import org.opendaylight.ovsdb.schema.openvswitch.Manager;
35 import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch;
36 import org.opendaylight.ovsdb.schema.openvswitch.Qos;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IetfInetUtil;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathId;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeBase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeSystem;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.InterfaceTypeBase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeProtocolBase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.QosTypeBase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntryBuilder;
58 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
59 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
60 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
61 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
62 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
63 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
64 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67
68 public class SouthboundMapper {
69     private static final Logger LOG = LoggerFactory.getLogger(SouthboundMapper.class);
70     private static final String N_CONNECTIONS_STR = "n_connections";
71
72     public static IpAddress createIpAddress(InetAddress address) {
73         IpAddress ip = null;
74         if (address instanceof Inet4Address) {
75             ip = createIpAddress((Inet4Address)address);
76         } else if (address instanceof Inet6Address) {
77             ip = createIpAddress((Inet6Address)address);
78         }
79         return ip;
80     }
81
82     public static IpAddress createIpAddress(Inet4Address address) {
83         return IetfInetUtil.INSTANCE.ipAddressFor(address);
84     }
85
86     public static IpAddress createIpAddress(Inet6Address address) {
87         Ipv6Address ipv6 = new Ipv6Address(address.getHostAddress());
88         return new IpAddress(ipv6);
89     }
90
91     public static InstanceIdentifier<Topology> createTopologyInstanceIdentifier() {
92         return InstanceIdentifier
93                 .create(NetworkTopology.class)
94                 .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID));
95     }
96
97     public static InstanceIdentifier<OvsdbBridgeAugmentation>
98         createBridgeInstanceIdentifier(OvsdbConnectionInstance client, String bridgeName) {
99         return createInstanceIdentifier(client, bridgeName).augmentation(OvsdbBridgeAugmentation.class);
100     }
101
102     public static InstanceIdentifier<Node> createInstanceIdentifier(NodeId nodeId) {
103         return createTopologyInstanceIdentifier()
104                 .child(Node.class,new NodeKey(nodeId));
105     }
106
107     @SuppressWarnings("unchecked")
108     public static InstanceIdentifier<Node> createInstanceIdentifier(OvsdbConnectionInstance client,Bridge bridge) {
109         InstanceIdentifier<Node> iid;
110         if (bridge.getExternalIdsColumn() != null
111                 && bridge.getExternalIdsColumn().getData() != null
112                 && bridge.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
113             String iidString = bridge.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
114             iid = (InstanceIdentifier<Node>) SouthboundUtil.deserializeInstanceIdentifier(iidString);
115         } else {
116             iid = createInstanceIdentifier(client, bridge.getName());
117         }
118         return iid;
119     }
120
121     @SuppressWarnings("unchecked")
122     public static InstanceIdentifier<Node> createInstanceIdentifier(
123             OvsdbConnectionInstance client, Controller controller, String bridgeName) {
124         InstanceIdentifier<Node> iid;
125         if (controller.getExternalIdsColumn() != null
126                 && controller.getExternalIdsColumn().getData() != null
127                 && controller.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
128             String iidString = controller.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
129             iid = (InstanceIdentifier<Node>) SouthboundUtil.deserializeInstanceIdentifier(iidString);
130         } else {
131             iid = createInstanceIdentifier(client, bridgeName);
132         }
133         return iid;
134     }
135
136     public static InstanceIdentifier<Node> createInstanceIdentifier(
137             OvsdbConnectionInstance client, String bridgeName) {
138         String nodeString = client.getNodeKey().getNodeId().getValue()
139                 + "/bridge/" + bridgeName;
140         NodeId nodeId = new NodeId(new Uri(nodeString));
141         return createInstanceIdentifier(nodeId);
142
143     }
144
145     public static NodeId createManagedNodeId(InstanceIdentifier<Node> iid) {
146         NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class);
147         return nodeKey.getNodeId();
148     }
149
150     public static InetAddress createInetAddress(IpAddress ip) throws UnknownHostException {
151         if (ip.getIpv4Address() != null) {
152             return InetAddresses.forString(ip.getIpv4Address().getValue());
153         } else if (ip.getIpv6Address() != null) {
154             return InetAddress.getByName(ip.getIpv6Address().getValue());
155         } else {
156             throw new UnknownHostException("IP Address has no value");
157         }
158     }
159
160     public static DatapathId createDatapathId(Bridge bridge) {
161         Preconditions.checkNotNull(bridge);
162         if (bridge.getDatapathIdColumn() == null) {
163             return null;
164         } else {
165             return createDatapathId(bridge.getDatapathIdColumn().getData());
166         }
167     }
168
169     public static DatapathId createDatapathId(Set<String> dpids) {
170         Preconditions.checkNotNull(dpids);
171         if (dpids.isEmpty()) {
172             return null;
173         } else {
174             String[] dpidArray = new String[dpids.size()];
175             dpids.toArray(dpidArray);
176             return createDatapathId(dpidArray[0]);
177         }
178     }
179
180     public static DatapathId createDatapathId(String dpid) {
181         Preconditions.checkNotNull(dpid);
182         DatapathId datapath;
183         if (dpid.matches("^[0-9a-fA-F]{16}")) {
184             Splitter splitter = Splitter.fixedLength(2);
185             Joiner joiner = Joiner.on(":");
186             datapath = new DatapathId(joiner.join(splitter.split(dpid)));
187         } else {
188             datapath = new DatapathId(dpid);
189         }
190         return datapath;
191     }
192
193     public static String createDatapathType(OvsdbBridgeAugmentation mdsalbridge) {
194         String datapathtype = SouthboundConstants.DATAPATH_TYPE_MAP.get(DatapathTypeSystem.class);
195
196         if (mdsalbridge.getDatapathType() != null && !mdsalbridge.getDatapathType().equals(DatapathTypeBase.class)) {
197             datapathtype = SouthboundConstants.DATAPATH_TYPE_MAP.get(mdsalbridge.getDatapathType());
198             if (datapathtype == null) {
199                 throw new IllegalArgumentException("Unknown datapath type " + mdsalbridge.getDatapathType().getName());
200             }
201         }
202         return datapathtype;
203     }
204
205     public static  Class<? extends DatapathTypeBase> createDatapathType(String type) {
206         Preconditions.checkNotNull(type);
207         if (type.isEmpty()) {
208             return DatapathTypeSystem.class;
209         } else {
210             ImmutableBiMap<String, Class<? extends DatapathTypeBase>> mapper =
211                     SouthboundConstants.DATAPATH_TYPE_MAP.inverse();
212             return mapper.get(type);
213         }
214     }
215
216     public static Set<String> createOvsdbBridgeProtocols(OvsdbBridgeAugmentation ovsdbBridgeNode) {
217         Set<String> protocols = new HashSet<>();
218         if (ovsdbBridgeNode.getProtocolEntry() != null && ovsdbBridgeNode.getProtocolEntry().size() > 0) {
219             for (ProtocolEntry protocol : ovsdbBridgeNode.getProtocolEntry()) {
220                 if (SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol()) != null) {
221                     protocols.add(SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol()));
222                 } else {
223                     throw new IllegalArgumentException("Unknown protocol " + protocol.getProtocol());
224                 }
225             }
226         }
227         return protocols;
228     }
229
230     public static  Class<? extends InterfaceTypeBase> createInterfaceType(String type) {
231         Preconditions.checkNotNull(type);
232         return SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.get(type);
233     }
234
235     public static String createOvsdbInterfaceType(Class<? extends InterfaceTypeBase> mdsaltype) {
236         Preconditions.checkNotNull(mdsaltype);
237         ImmutableBiMap<Class<? extends InterfaceTypeBase>, String> mapper =
238                 SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.inverse();
239         return mapper.get(mdsaltype);
240     }
241
242     public static List<ProtocolEntry> createMdsalProtocols(Bridge bridge) {
243         Set<String> protocols = null;
244         try {
245             protocols = bridge.getProtocolsColumn().getData();
246         } catch (SchemaVersionMismatchException e) {
247             schemaMismatchLog("protocols", "Bridge", e);
248         }
249         List<ProtocolEntry> protocolList = new ArrayList<>();
250         if (protocols != null && protocols.size() > 0) {
251             ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
252                     SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse();
253             for (String protocol : protocols) {
254                 if (protocol != null && mapper.get(protocol) != null) {
255                     protocolList.add(new ProtocolEntryBuilder().setProtocol(mapper.get(protocol)).build());
256                 }
257             }
258         }
259         return protocolList;
260     }
261
262     /**
263      * Create the {@link ControllerEntry} list given an OVSDB {@link Bridge}
264      * and {@link Controller} rows.
265      *
266      * @param bridge the {@link Bridge} to update
267      * @param updatedControllerRows the list of {@link Controller} controllers with updates
268      * @return list of {@link ControllerEntry} entries
269      */
270     public static List<ControllerEntry> createControllerEntries(Bridge bridge,
271                                                                 Map<UUID, Controller> updatedControllerRows) {
272
273         LOG.debug("createControllerEntries Bridge: {}\n, updatedControllerRows: {}",
274                 bridge, updatedControllerRows);
275         final Set<UUID> controllerUuids = bridge.getControllerColumn().getData();
276         final List<ControllerEntry> controllerEntries = new ArrayList<>();
277         for (UUID controllerUuid : controllerUuids ) {
278             final Controller controller = updatedControllerRows.get(controllerUuid);
279             addControllerEntries(controllerEntries, controller);
280         }
281         LOG.debug("controllerEntries: {}", controllerEntries);
282         return controllerEntries;
283     }
284
285     /**
286      * Create the {@link ControllerEntry} list given an MDSAL {@link Node} bridge
287      * and {@link Controller} rows.
288      *
289      * @param bridgeNode the {@link Node} to update
290      * @param updatedControllerRows the list of {@link Controller} controllers with updates
291      * @return list of {@link ControllerEntry} entries
292      */
293     public static List<ControllerEntry> createControllerEntries(Node bridgeNode,
294                                                                 Map<UUID, Controller> updatedControllerRows) {
295
296         LOG.debug("createControllerEntries Bridge 2: {}\n, updatedControllerRows: {}",
297                 bridgeNode, updatedControllerRows);
298         final List<ControllerEntry> controllerEntriesCreated = new ArrayList<>();
299         final OvsdbBridgeAugmentation ovsdbBridgeAugmentation =
300                 bridgeNode.getAugmentation(OvsdbBridgeAugmentation.class);
301         if (ovsdbBridgeAugmentation == null) {
302             return controllerEntriesCreated;
303         }
304
305         final List<ControllerEntry> controllerEntries = ovsdbBridgeAugmentation.getControllerEntry();
306         if (controllerEntries != null) {
307             for (ControllerEntry controllerEntry : controllerEntries) {
308                 final Controller controller = updatedControllerRows.get(
309                         new UUID(controllerEntry.getControllerUuid().getValue()));
310                 addControllerEntries(controllerEntriesCreated, controller);
311             }
312         }
313         LOG.debug("controllerEntries: {}", controllerEntriesCreated);
314         return controllerEntriesCreated;
315     }
316
317     /**
318      * Add the OVSDB {@link Controller} updates to the MDSAL {@link ControllerEntry} list.
319      *
320      * @param controllerEntries the list of {@link ControllerEntry} to update
321      * @param controller the updated OVSDB {@link Controller}
322      */
323     public static void addControllerEntries(List<ControllerEntry> controllerEntries,
324                                             final Controller controller) {
325
326         if (controller != null && controller.getTargetColumn() != null) {
327             final String targetString = controller.getTargetColumn().getData();
328             final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid uuid =
329                     new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
330                             .ietf.yang.types.rev130715.Uuid(controller.getUuid().toString());
331
332             controllerEntries.add(new ControllerEntryBuilder()
333                     .setTarget(new Uri(targetString))
334                     .setIsConnected(controller.getIsConnectedColumn().getData())
335                     .setControllerUuid(uuid).build());
336         }
337     }
338
339     public static Map<UUID, Controller> createOvsdbController(OvsdbBridgeAugmentation omn,DatabaseSchema dbSchema) {
340         List<ControllerEntry> controllerEntries = omn.getControllerEntry();
341         Map<UUID,Controller> controllerMap = new HashMap<>();
342         if (controllerEntries != null && !controllerEntries.isEmpty()) {
343             for (ControllerEntry controllerEntry : controllerEntries) {
344                 String controllerNamedUuid = "Controller_" + getRandomUuid();
345                 Controller controller = TyperUtils.getTypedRowWrapper(dbSchema, Controller.class);
346                 controller.setTarget(controllerEntry.getTarget().getValue());
347                 controllerMap.put(new UUID(controllerNamedUuid), controller);
348             }
349         }
350         return controllerMap;
351     }
352
353     public static String getRandomUuid() {
354         return "Random_" + java.util.UUID.randomUUID().toString().replace("-", "");
355     }
356
357     public static ConnectionInfo createConnectionInfo(OvsdbClient client) {
358         ConnectionInfoBuilder connectionInfoBuilder = new ConnectionInfoBuilder();
359         connectionInfoBuilder.setRemoteIp(createIpAddress(client.getConnectionInfo().getRemoteAddress()));
360         connectionInfoBuilder.setRemotePort(new PortNumber(client.getConnectionInfo().getRemotePort()));
361         connectionInfoBuilder.setLocalIp(createIpAddress(client.getConnectionInfo().getLocalAddress()));
362         connectionInfoBuilder.setLocalPort(new PortNumber(client.getConnectionInfo().getLocalPort()));
363         return connectionInfoBuilder.build();
364     }
365
366     public static ConnectionInfo suppressLocalIpPort(ConnectionInfo connectionInfo) {
367         ConnectionInfoBuilder connectionInfoBuilder = new ConnectionInfoBuilder();
368         connectionInfoBuilder.setRemoteIp(connectionInfo.getRemoteIp());
369         connectionInfoBuilder.setRemotePort(connectionInfo.getRemotePort());
370         return connectionInfoBuilder.build();
371     }
372
373     /**
374      * Create the {@link ManagerEntry} list given an OVSDB {@link OpenVSwitch}
375      * and {@link Manager} rows.
376      *
377      * @param ovsdbNode the {@link OpenVSwitch} to update
378      * @param updatedManagerRows the list of {@link Manager} managers with updates
379      * @return list of {@link ManagerEntry} entries
380      */
381     public static List<ManagerEntry> createManagerEntries(OpenVSwitch ovsdbNode,
382                                                                 Map<UUID, Manager> updatedManagerRows) {
383
384         LOG.debug("createManagerEntries OpenVSwitch: {}\n, updatedManagerRows: {}",
385                 ovsdbNode, updatedManagerRows);
386         final Set<UUID> managerUuids = ovsdbNode.getManagerOptionsColumn().getData();
387         final List<ManagerEntry> managerEntries = new ArrayList<>();
388         for (UUID managerUuid : managerUuids) {
389             final Manager manager = updatedManagerRows.get(managerUuid);
390             addManagerEntries(managerEntries, manager);
391         }
392         LOG.debug("managerEntries: {}", managerEntries);
393         return managerEntries;
394     }
395
396     /**
397      * Create the {@link ManagerEntry} list given an MDSAL {@link Node} ovsdbNode
398      * and {@link Manager} rows.
399      *
400      * @param ovsdbNode the {@link Node} to update
401      * @param updatedManagerRows the list of {@link Manager} managers with updates
402      * @return list of {@link ManagerEntry} entries
403      */
404     public static List<ManagerEntry> createManagerEntries(Node ovsdbNode,
405                                                                 Map<Uri, Manager> updatedManagerRows) {
406
407         LOG.debug("createManagerEntries based on OVSDB Node: {}\n, updatedManagerRows: {}",
408                 ovsdbNode, updatedManagerRows);
409         final List<ManagerEntry> managerEntriesCreated = new ArrayList<>();
410         final OvsdbNodeAugmentation ovsdbNodeAugmentation =
411                 ovsdbNode.getAugmentation(OvsdbNodeAugmentation.class);
412         if (ovsdbNodeAugmentation == null) {
413             return managerEntriesCreated;
414         }
415
416         final List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
417         if (managerEntries != null) {
418             for (ManagerEntry managerEntry : managerEntries) {
419                 final Manager manager = updatedManagerRows.get(managerEntry.getTarget());
420                 addManagerEntries(managerEntriesCreated, manager);
421             }
422         }
423         LOG.debug("managerEntries: {}", managerEntriesCreated);
424         return managerEntriesCreated;
425     }
426
427     /**
428      * Add the OVSDB {@link Manager} updates to the MDSAL {@link ManagerEntry} list.
429      *
430      * @param managerEntries the list of {@link ManagerEntry} to update
431      * @param manager the updated OVSDB {@link Manager}
432      */
433     public static void addManagerEntries(List<ManagerEntry> managerEntries,
434                                             final Manager manager) {
435
436         if (manager != null && manager.getTargetColumn() != null) {
437             long numberOfConnections = 0;
438             final String targetString = manager.getTargetColumn().getData();
439
440             final Map<String, String> statusAttributeMap = manager.getStatusColumn().getData();
441             if (statusAttributeMap.containsKey(N_CONNECTIONS_STR)) {
442                 String numberOfConnectionValueStr = statusAttributeMap.get(N_CONNECTIONS_STR);
443                 numberOfConnections = Integer.parseInt(numberOfConnectionValueStr);
444             } else {
445                 final boolean isConnected = manager.getIsConnectedColumn().getData();
446                 if (isConnected) {
447                     numberOfConnections = 1;
448                 }
449             }
450             managerEntries.add(new ManagerEntryBuilder()
451                     .setTarget(new Uri(targetString))
452                     .setNumberOfConnections(numberOfConnections)
453                     .setConnected(manager.getIsConnectedColumn().getData()).build());
454         }
455     }
456
457     /**
458      * Return the MD-SAL QoS type class corresponding to the QoS type {@link Qos}.
459      *
460      * @param type the QoS type to match {@link String}
461      * @return class matching the input QoS type {@link QosTypeBase}
462      */
463     public static  Class<? extends QosTypeBase> createQosType(String type) {
464         Preconditions.checkNotNull(type);
465         if (type.isEmpty()) {
466             LOG.info("QoS type not supplied");
467             return QosTypeBase.class;
468         } else {
469             ImmutableBiMap<String, Class<? extends QosTypeBase>> mapper =
470                     SouthboundConstants.QOS_TYPE_MAP.inverse();
471             if (mapper.get(type) == null) {
472                 LOG.info("QoS type not found in model: {}", type);
473                 return QosTypeBase.class;
474             } else {
475                 return mapper.get(type);
476             }
477         }
478     }
479
480     public static String createQosType(Class<? extends QosTypeBase> qosTypeClass) {
481         String qosType = SouthboundConstants.QOS_TYPE_MAP.get(QosTypeBase.class);
482
483         if (qosTypeClass != null && !qosTypeClass.equals(QosTypeBase.class)) {
484             qosType = SouthboundConstants.QOS_TYPE_MAP.get(qosTypeClass);
485             if (qosType == null) {
486                 throw new IllegalArgumentException("Unknown QoS type" + qosTypeClass.getName());
487             }
488         }
489         return qosType;
490     }
491
492
493     public static InstanceIdentifier<Node> getInstanceIdentifier(OpenVSwitch ovs) {
494         if (ovs.getExternalIdsColumn() != null
495                 && ovs.getExternalIdsColumn().getData() != null
496                 && ovs.getExternalIdsColumn().getData().containsKey(SouthboundConstants.IID_EXTERNAL_ID_KEY)) {
497             String iidString = ovs.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY);
498             return (InstanceIdentifier<Node>) SouthboundUtil.deserializeInstanceIdentifier(iidString);
499         } else {
500             String nodeString = SouthboundConstants.OVSDB_URI_PREFIX + "://" + SouthboundConstants.UUID + "/"
501                     + ovs.getUuid().toString();
502             NodeId nodeId = new NodeId(new Uri(nodeString));
503             NodeKey nodeKey = new NodeKey(nodeId);
504             return InstanceIdentifier.builder(NetworkTopology.class)
505                     .child(Topology.class,new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
506                     .child(Node.class,nodeKey)
507                     .build();
508         }
509     }
510 }