X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=southbound%2Fsouthbound-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Fsouthbound%2FSouthboundMapper.java;h=f4e4580a6a21862504c4fc1562c35daccd1699ad;hb=refs%2Fchanges%2F58%2F18058%2F2;hp=d873841c8a85a481bca7a88dbc54f6689378afc1;hpb=d2dde139dee15d4c4f9d419f5fe23ca6f8c0da53;p=ovsdb.git diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundMapper.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundMapper.java index d873841c8..f4e4580a6 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundMapper.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundMapper.java @@ -31,6 +31,9 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. 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.DatapathId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeBase; +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; @@ -42,7 +45,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re 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.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.TpId; 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; @@ -86,7 +88,7 @@ public class SouthboundMapper { public static IpAddress createIpAddress(InetAddress address) { IpAddress ip = null; - if(address instanceof Inet4Address) { + if (address instanceof Inet4Address) { ip = createIpAddress((Inet4Address)address); } else if (address instanceof Inet6Address) { ip = createIpAddress((Inet6Address)address); @@ -121,6 +123,27 @@ public class SouthboundMapper { return createInstanceIdentifier(createManagedNodeId(key, bridgeName)); } + public static InstanceIdentifier createInstanceIdentifier(OvsdbClientKey key,Bridge bridge) { + String managedNodePathString = bridge + .getExternalIdsColumn() + .getData() + .get(SouthboundConstants.IID_EXTERNAL_ID_KEY); + InstanceIdentifier managedNodePath = null; + if (managedNodePathString != null) { + managedNodePath = (InstanceIdentifier) SouthboundUtil + .deserializeInstanceIdentifier(managedNodePathString); + } + if (managedNodePath == null) { + managedNodePath = SouthboundMapper.createInstanceIdentifier(key,new OvsdbBridgeName(bridge.getName())); + } + return managedNodePath; + } + + public static NodeId createManagedNodeId(InstanceIdentifier iid) { + NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class); + return nodeKey.getNodeId(); + } + public static InstanceIdentifier createInstanceIdentifier(OvsdbClientKey key) { return createInstanceIdentifier(key.getIp(), key.getPort()); } @@ -130,7 +153,7 @@ public class SouthboundMapper { .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) .child(Node.class,createNodeKey(ip,port)); - LOG.info("Created ovsdb path: {}",path); + LOG.debug("Created ovsdb path: {}",path); return path; } @@ -155,37 +178,21 @@ public class SouthboundMapper { public static NodeId createManagedNodeId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName) { return new NodeId(createNodeId(ip,port).getValue() - + "/"+SouthboundConstants.BRIDGE_URI_PREFIX+"/"+ bridgeName.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(); + 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 TpId createTerminationPointId(OvsdbConnectionInfo connectionInfo, OvsdbBridgeName bridgeName, String tpName) { - return createTerminationPointId(createIpAddress(connectionInfo.getRemoteAddress()), - new PortNumber(connectionInfo.getRemotePort()), - bridgeName, tpName); - } - - public static TpId createTerminationPointId(OvsdbClientKey key, OvsdbBridgeName bridgeName, String tpName) { - return createTerminationPointId(key.getIp(),key.getPort(),bridgeName, tpName); - } - - public static TpId createTerminationPointId(IpAddress ip, PortNumber port, OvsdbBridgeName bridgeName, String tpName) { - return new TpId(createNodeId(ip,port).getValue() - + "/"+SouthboundConstants.BRIDGE_URI_PREFIX+"/"+ bridgeName.getValue() - + "/"+SouthboundConstants.TP_URI_PREFIX+"/"+ tpName); - } - public static InetAddress createInetAddress(IpAddress ip) throws UnknownHostException { - if(ip.getIpv4Address() != null) { + if (ip.getIpv4Address() != null) { return InetAddress.getByName(ip.getIpv4Address().getValue()); - } else if(ip.getIpv6Address() != null) { + } else if (ip.getIpv6Address() != null) { return InetAddress.getByName(ip.getIpv6Address().getValue()); } else { throw new UnknownHostException("IP Address has no value"); @@ -194,7 +201,7 @@ public class SouthboundMapper { public static DatapathId createDatapathId(Bridge bridge) { Preconditions.checkNotNull(bridge); - if(bridge.getDatapathIdColumn() == null) { + if (bridge.getDatapathIdColumn() == null) { return null; } else { return createDatapathId(bridge.getDatapathIdColumn().getData()); @@ -203,7 +210,7 @@ public class SouthboundMapper { public static DatapathId createDatapathId(Set dpids) { Preconditions.checkNotNull(dpids); - if(dpids.isEmpty()) { + if (dpids.isEmpty()) { return null; } else { String[] dpidArray = new String[dpids.size()]; @@ -212,10 +219,35 @@ public class SouthboundMapper { } } + public static String createDatapathType(OvsdbBridgeAugmentation mdsalbridge) { + String datapathtype = new String(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())); + } + } + return datapathtype; + } + + public static Class createDatapathType(String type) { + Preconditions.checkNotNull(type); + if (type.isEmpty()) { + return DatapathTypeSystem.class; + } else { + ImmutableBiMap> mapper = + SouthboundConstants.DATAPATH_TYPE_MAP.inverse(); + return mapper.get(type); + } + } + public static DatapathId createDatapathId(String dpid) { Preconditions.checkNotNull(dpid); DatapathId datapath; - if(dpid.matches("^[0-9a-fA-F]{16}")) { + 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))); @@ -227,9 +259,9 @@ public class SouthboundMapper { public static Set createOvsdbBridgeProtocols(OvsdbBridgeAugmentation ovsdbBridgeNode) { Set 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) { + if (ovsdbBridgeNode.getProtocolEntry() != null && ovsdbBridgeNode.getProtocolEntry().size() > 0) { + for (ProtocolEntry protocol : ovsdbBridgeNode.getProtocolEntry()) { + if (SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol()) != null) { protocols.add(SouthboundConstants.OVSDB_PROTOCOL_MAP.get(protocol.getProtocol())); } else { throw new IllegalArgumentException("Unknown protocol " + protocol.getProtocol()); @@ -239,30 +271,50 @@ public class SouthboundMapper { return protocols; } + public static Class createInterfaceType(String type) { + Preconditions.checkNotNull(type); + return SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.get(type); + } + + public static String createOvsdbInterfaceType(Class mdsaltype) { + Preconditions.checkNotNull(mdsaltype); + ImmutableBiMap, String> mapper = + SouthboundConstants.OVSDB_INTERFACE_TYPE_MAP.inverse(); + return mapper.get(mdsaltype); + } + public static List createMdsalProtocols(Bridge bridge) { Set protocols = bridge.getProtocolsColumn().getData(); List protocolList = new ArrayList(); - if(protocols != null && protocols.size() >0) { - ImmutableBiMap> mapper = SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse(); - for(String protocol : protocols) { - if(protocol != null && mapper.get(protocol) != null) { - protocolList.add(new ProtocolEntryBuilder().setProtocol((Class) mapper.get(protocol)).build()); + if (protocols != null && protocols.size() > 0) { + ImmutableBiMap> mapper = + SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse(); + for (String protocol : protocols) { + if (protocol != null && mapper.get(protocol) != null) { + protocolList.add(new ProtocolEntryBuilder(). + setProtocol((Class) mapper.get(protocol)).build()); } } } return protocolList; } - public static List createControllerEntries(Bridge bridge,Map updatedControllerRows) { - LOG.info("Bridge: {}, updatedControllerRows: {}",bridge,updatedControllerRows); + public static List createControllerEntries(Bridge bridge,Map updatedControllerRows) { + LOG.debug("Bridge: {}, updatedControllerRows: {}",bridge,updatedControllerRows); Set controllerUUIDs = bridge.getControllerColumn().getData(); List controllerEntries = new ArrayList(); - for(UUID controllerUUID : controllerUUIDs ) { + for (UUID controllerUUID : controllerUUIDs ) { Controller controller = updatedControllerRows.get(controllerUUID); - if(controller != null && controller.getTargetColumn() != null + if (controller != null && controller.getTargetColumn() != null && controller.getTargetColumn() != null) { String targetString = controller.getTargetColumn().getData(); - controllerEntries.add(new ControllerEntryBuilder().setTarget(new Uri(targetString)).build()); + 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() + .setTarget(new Uri(targetString)) + .setControllerUuid(uuid).build()); } } return controllerEntries; @@ -271,10 +323,10 @@ public class SouthboundMapper { public static Map createOvsdbController(OvsdbBridgeAugmentation omn,DatabaseSchema dbSchema) { List controllerEntries = omn.getControllerEntry(); Map controllerMap = new HashMap(); - if(controllerEntries != null && !controllerEntries.isEmpty()) { + if (controllerEntries != null && !controllerEntries.isEmpty()) { int index = 0; - for(ControllerEntry controllerEntry : controllerEntries) { - String controllerNamedUUID = "Controller_" + omn.getBridgeName().getValue() + index++; + for (ControllerEntry controllerEntry : controllerEntries) { + String controllerNamedUUID = "Controller_" + getRandomUUID(); Controller controller = TyperUtils.getTypedRowWrapper(dbSchema, Controller.class); controller.setTarget(controllerEntry.getTarget().getValue()); controllerMap.put(new UUID(controllerNamedUUID), controller); @@ -282,4 +334,8 @@ public class SouthboundMapper { } return controllerMap; } + + public static String getRandomUUID() { + return java.util.UUID.randomUUID().toString().replace("-", ""); + } }