X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=southbound%2Fsouthbound-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Fsouthbound%2FSouthboundMapper.java;h=cb2b4cd74ea0af9e2cf8d3ccf5e81e5b4b371367;hb=50e7f939993fa9da3c80a1c8d166629a4868af9c;hp=7f858c39fbe723043fa27371bad09b0f6c483a05;hpb=9fbb4ee65615591a6fafc729f2d13687e4beeb60;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 7f858c39f..cb2b4cd74 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 @@ -7,6 +7,13 @@ */ 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; @@ -17,7 +24,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - import org.opendaylight.ovsdb.lib.OvsdbClient; import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException; import org.opendaylight.ovsdb.lib.notation.UUID; @@ -28,8 +34,8 @@ 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; @@ -59,11 +65,6 @@ 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); private static final String N_CONNECTIONS_STR = "n_connections"; @@ -79,8 +80,7 @@ public class SouthboundMapper { } 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) { @@ -88,13 +88,23 @@ public class SouthboundMapper { return new IpAddress(ipv6); } - public static InstanceIdentifier createInstanceIdentifier(NodeId nodeId) { + public static InstanceIdentifier createTopologyInstanceIdentifier() { return InstanceIdentifier .create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) + .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)); + } + + public static InstanceIdentifier + createBridgeInstanceIdentifier(OvsdbConnectionInstance client, String bridgeName) { + return createInstanceIdentifier(client, bridgeName).augmentation(OvsdbBridgeAugmentation.class); + } + + public static InstanceIdentifier createInstanceIdentifier(NodeId nodeId) { + return createTopologyInstanceIdentifier() .child(Node.class,new NodeKey(nodeId)); } + @SuppressWarnings("unchecked") public static InstanceIdentifier createInstanceIdentifier(OvsdbConnectionInstance client,Bridge bridge) { InstanceIdentifier iid; if (bridge.getExternalIdsColumn() != null @@ -103,18 +113,12 @@ public class SouthboundMapper { String iidString = bridge.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY); iid = (InstanceIdentifier) SouthboundUtil.deserializeInstanceIdentifier(iidString); } else { - String nodeString = client.getNodeKey().getNodeId().getValue() - + "/bridge/" + bridge.getName(); - NodeId nodeId = new NodeId(new Uri(nodeString)); - NodeKey nodeKey = new NodeKey(nodeId); - iid = InstanceIdentifier.builder(NetworkTopology.class) - .child(Topology.class,new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) - .child(Node.class,nodeKey) - .build(); + iid = createInstanceIdentifier(client, bridge.getName()); } return iid; } + @SuppressWarnings("unchecked") public static InstanceIdentifier createInstanceIdentifier( OvsdbConnectionInstance client, Controller controller, String bridgeName) { InstanceIdentifier iid; @@ -124,19 +128,20 @@ public class SouthboundMapper { String iidString = controller.getExternalIdsColumn().getData().get(SouthboundConstants.IID_EXTERNAL_ID_KEY); iid = (InstanceIdentifier) SouthboundUtil.deserializeInstanceIdentifier(iidString); } else { - // TODO retrieve bridge name - String nodeString = client.getNodeKey().getNodeId().getValue() - + "/bridge/" + bridgeName; - NodeId nodeId = new NodeId(new Uri(nodeString)); - NodeKey nodeKey = new NodeKey(nodeId); - iid = InstanceIdentifier.builder(NetworkTopology.class) - .child(Topology.class,new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)) - .child(Node.class,nodeKey) - .build(); + iid = createInstanceIdentifier(client, bridgeName); } return iid; } + public static InstanceIdentifier 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 createManagedNodeId(InstanceIdentifier iid) { NodeKey nodeKey = iid.firstKeyOf(Node.class, NodeKey.class); return nodeKey.getNodeId(); @@ -144,7 +149,7 @@ public class SouthboundMapper { 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 { @@ -172,6 +177,19 @@ public class SouthboundMapper { } } + 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 = SouthboundConstants.DATAPATH_TYPE_MAP.get(DatapathTypeSystem.class); @@ -195,19 +213,6 @@ public class SouthboundMapper { } } - 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 createOvsdbBridgeProtocols(OvsdbBridgeAugmentation ovsdbBridgeNode) { Set protocols = new HashSet<>(); if (ovsdbBridgeNode.getProtocolEntry() != null && ovsdbBridgeNode.getProtocolEntry().size() > 0) { @@ -239,8 +244,7 @@ public class SouthboundMapper { try { protocols = bridge.getProtocolsColumn().getData(); } catch (SchemaVersionMismatchException e) { - // We don't care about the exception stack trace here - LOG.warn("protocols not supported by this version of ovsdb: {}", e.getMessage()); + schemaMismatchLog("protocols", "Bridge", e); } List protocolList = new ArrayList<>(); if (protocols != null && protocols.size() > 0) { @@ -248,8 +252,7 @@ public class SouthboundMapper { SouthboundConstants.OVSDB_PROTOCOL_MAP.inverse(); for (String protocol : protocols) { if (protocol != null && mapper.get(protocol) != null) { - protocolList.add(new ProtocolEntryBuilder(). - setProtocol(mapper.get(protocol)).build()); + protocolList.add(new ProtocolEntryBuilder().setProtocol(mapper.get(protocol)).build()); } } } @@ -269,10 +272,10 @@ public class SouthboundMapper { LOG.debug("createControllerEntries Bridge: {}\n, updatedControllerRows: {}", bridge, updatedControllerRows); - final Set controllerUUIDs = bridge.getControllerColumn().getData(); + final Set controllerUuids = bridge.getControllerColumn().getData(); final List controllerEntries = new ArrayList<>(); - for (UUID controllerUUID : controllerUUIDs ) { - final Controller controller = updatedControllerRows.get(controllerUUID); + for (UUID controllerUuid : controllerUuids ) { + final Controller controller = updatedControllerRows.get(controllerUuid); addControllerEntries(controllerEntries, controller); } LOG.debug("controllerEntries: {}", controllerEntries); @@ -338,18 +341,19 @@ public class SouthboundMapper { Map controllerMap = new HashMap<>(); if (controllerEntries != null && !controllerEntries.isEmpty()) { 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())); @@ -379,10 +383,10 @@ public class SouthboundMapper { LOG.debug("createManagerEntries OpenVSwitch: {}\n, updatedManagerRows: {}", ovsdbNode, updatedManagerRows); - final Set managerUUIDs = ovsdbNode.getManagerOptionsColumn().getData(); + final Set managerUuids = ovsdbNode.getManagerOptionsColumn().getData(); final List managerEntries = new ArrayList<>(); - for (UUID managerUUID : managerUUIDs ) { - final Manager manager = updatedManagerRows.get(managerUUID); + for (UUID managerUuid : managerUuids) { + final Manager manager = updatedManagerRows.get(managerUuid); addManagerEntries(managerEntries, manager); } LOG.debug("managerEntries: {}", managerEntries); @@ -451,7 +455,7 @@ public class SouthboundMapper { } /** - * Return the MD-SAL QoS type class corresponding to the QoS type {@link Qos} + * 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}