Fix license header violations in hosttracker
[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)
41                         .setDestTp(dstTpId).build())//
42                 .setLinkId(new LinkId(srcTpId.getValue() + "/" + dstTpId.getValue()));
43         srcdst.setKey(new LinkKey(srcdst.getLinkId()));
44         LinkBuilder dstsrc = new LinkBuilder()//
45                 .setSource(new SourceBuilder()//
46                         .setSourceNode(dstNId)//
47                         .setSourceTp(dstTpId).build())//
48                 .setDestination(new DestinationBuilder()//
49                         .setDestNode(srcNId)
50                         .setDestTp(srcTpId).build())//
51                 .setLinkId(new LinkId(dstTpId.getValue() + "/" + srcTpId.getValue()));
52         dstsrc.setKey(new LinkKey(dstsrc.getLinkId()));
53         links.add(dstsrc.build());
54         links.add(srcdst.build());
55         return links;
56     }
57
58     public static InstanceIdentifier<Node> buildNodeIID(NodeKey nk, String topologyId) {
59         InstanceIdentifier<Node> nIID = InstanceIdentifier.builder(NetworkTopology.class)//
60                 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))//
61                 .child(Node.class, nk).build();
62         return nIID;
63     }
64
65     public static InstanceIdentifier<Link> buildLinkIID(LinkKey lk, String topologyId) {
66         InstanceIdentifier<Link> lIID = InstanceIdentifier.builder(NetworkTopology.class)//
67                 .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))//
68                 .child(Link.class, lk).build();
69         return lIID;
70     }
71
72     public static AttachmentPointsBuilder createAPsfromNodeConnector(NodeConnector nc) {
73         TpId tpId = new TpId(nc.getId().getValue());
74         return createAPsfromTP(tpId);
75     }
76
77     public static AttachmentPointsBuilder createAPsfromTP(TpId tpId) {
78         AttachmentPointsBuilder at = new AttachmentPointsBuilder()//
79                 .setTpId(tpId)//
80                 .setKey(new AttachmentPointsKey(tpId));
81         return at;
82     }
83 }