c4bc55b7628a6ba8480c46e5ef7f6658d685b74d
[l2switch.git] / hosttracker / implementation / src / main / java / org / opendaylight / l2switch / hosttracker / plugin / util / Utilities.java
1 /**
2  * Copyright (c) 2014 AndrĂ© Martins, Colin Dixon, Evan Zeller 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.l2switch.hosttracker.plugin.util;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.host.AttachmentPointsBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.host.AttachmentPointsKey;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
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.Link;
25 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
26 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 public class Utilities {
32
33     public static List<Link> createLinks(NodeId srcNId, TpId srcTpId, NodeId dstNId, TpId dstTpId) {
34         List<Link> links = new ArrayList();
35         LinkBuilder srcdst = new LinkBuilder()//
36                 .setSource(new SourceBuilder()//
37                         .setSourceNode(srcNId)//
38                         .setSourceTp(srcTpId).build())//
39                 .setDestination(new DestinationBuilder()//
40                         .setDestNode(dstNId).setDestTp(dstTpId).build())//
41                 .setLinkId(new LinkId(srcTpId.getValue() + "/" + dstTpId.getValue()));
42         srcdst.setKey(new LinkKey(srcdst.getLinkId()));
43         LinkBuilder dstsrc = new LinkBuilder()//
44                 .setSource(new SourceBuilder()//
45                         .setSourceNode(dstNId)//
46                         .setSourceTp(dstTpId).build())//
47                 .setDestination(new DestinationBuilder()//
48                         .setDestNode(srcNId).setDestTp(srcTpId).build())//
49                 .setLinkId(new LinkId(dstTpId.getValue() + "/" + srcTpId.getValue()));
50         dstsrc.setKey(new LinkKey(dstsrc.getLinkId()));
51         links.add(dstsrc.build());
52         links.add(srcdst.build());
53         return links;
54     }
55
56     public static InstanceIdentifier<Node> buildNodeIID(NodeKey nk, String topologyId) {
57         InstanceIdentifier<Node> nIID = InstanceIdentifier.builder(NetworkTopology.class)//
58                 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))//
59                 .child(Node.class, nk).build();
60         return nIID;
61     }
62
63     public static InstanceIdentifier<Link> buildLinkIID(LinkKey lk, String topologyId) {
64         InstanceIdentifier<Link> lIID = InstanceIdentifier.builder(NetworkTopology.class)//
65                 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))//
66                 .child(Link.class, lk).build();
67         return lIID;
68     }
69
70     public static AttachmentPointsBuilder createAPsfromNodeConnector(NodeConnector nc) {
71         TpId tpId = new TpId(nc.getId().getValue());
72         return createAPsfromTP(tpId);
73     }
74
75     public static AttachmentPointsBuilder createAPsfromTP(TpId tpId) {
76         AttachmentPointsBuilder at = new AttachmentPointsBuilder()//
77                 .setTpId(tpId)//
78                 .setKey(new AttachmentPointsKey(tpId));
79         return at;
80     }
81 }