2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.utils.hwvtepsouthbound.utils;
11 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants;
12 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public final class HwvtepSouthboundUtils {
32 private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundUtils.class);
34 private HwvtepSouthboundUtils() {
37 public static NodeId createNodeId(IpAddress ip, PortNumber port) {
38 String uriString = HwvtepSouthboundConstants.HWVTEP_URI_PREFIX + "://"
39 + ip.stringValue() + ":" + port.getValue();
40 Uri uri = new Uri(uriString);
41 return new NodeId(uri);
44 public static Node createNode(ConnectionInfo key) {
45 return new NodeBuilder()
46 .setNodeId(createNodeId(key.getRemoteIp(), key.getRemotePort()))
47 .addAugmentation(createHwvtepAugmentation(key))
51 public static HwvtepGlobalAugmentation createHwvtepAugmentation(ConnectionInfo key) {
52 return new HwvtepGlobalAugmentationBuilder().setConnectionInfo(key).build();
55 public static InstanceIdentifier<Node> createInstanceIdentifier(ConnectionInfo key) {
56 return createInstanceIdentifier(key.getRemoteIp(), key.getRemotePort());
59 public static InstanceIdentifier<Node> createInstanceIdentifier(IpAddress ip, PortNumber port) {
60 InstanceIdentifier<Node> path = InstanceIdentifier
61 .create(NetworkTopology.class)
62 .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID))
63 .child(Node.class,createNodeKey(ip,port));
64 LOG.debug("Created hwvtep path: {}",path);
68 public static InstanceIdentifier<Node> createInstanceIdentifier(ConnectionInfo key, HwvtepNodeName name) {
69 return HwvtepSouthboundMapper.createInstanceIdentifier(
70 createManagedNodeId(key, name));
73 private static NodeId createManagedNodeId(ConnectionInfo key, HwvtepNodeName nodeName) {
74 return createManagedNodeId(key.getRemoteIp(), key.getRemotePort(), nodeName);
77 private static NodeId createManagedNodeId(IpAddress remoteIp, PortNumber remotePort, HwvtepNodeName nodeName) {
78 //This assumes that HwvtepNode can only be Physical switch
79 return new NodeId(createNodeId(remoteIp,remotePort).getValue()
80 + "/" + HwvtepSouthboundConstants.PSWITCH_URI_PREFIX + "/" + nodeName.getValue());
83 public static NodeKey createNodeKey(IpAddress ip, PortNumber port) {
84 return new NodeKey(createNodeId(ip, port));
87 public static Object connectionInfoToString(ConnectionInfo connectionInfo) {
88 return connectionInfo.getRemoteIp().stringValue() + ":" + connectionInfo.getRemotePort().getValue();