76e40b79a8ddf18908ab55820fbd9810526797d4
[transportpce.git] / tests / stubpce / src / main / java / org / opendaylight / transportpce / stubpce / TpNodeTp.java
1 /*
2  * Copyright © 2017 Orange, Inc. 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
9 package org.opendaylight.transportpce.stubpce;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZ;
15 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZBuilder;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZKey;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToA;
18 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToABuilder;
19 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToAKey;
20 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.Resource;
21 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.ResourceBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Node;
23 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
24
25 /**
26  * Class to create structure
27  * TerminationPoint
28  * Node
29  * TerminationPoint.
30  *
31  * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
32  *         behalf of Orange
33  */
34 public class TpNodeTp {
35     private TerminationPoint tpOut;
36     private TerminationPoint tpIn;
37     private Node node;
38     private List<Resource> resources;
39     private List<AToZ> atoz;
40     private List<ZToA> ztoa;
41     private List<String> ids;
42
43     /**
44      * TpNodeTp Constructor.
45      *
46      * @param in TerminationPoint input
47      * @param out TerminationPoint output
48      * @param node Node Id
49      */
50     public TpNodeTp(TerminationPoint in, TerminationPoint out, Node node) {
51         this.tpOut = out;
52         this.tpIn = in;
53         this.node = node;
54         resources = new ArrayList<Resource>();
55         atoz = new ArrayList<AToZ>();
56         ztoa = new ArrayList<ZToA>();
57         ids = new ArrayList<String>();
58
59     }
60
61     /**
62      * create resource List.
63      */
64     public void createListResource() {
65         ids.clear();
66         resources.clear();
67         atoz.clear();
68         ztoa.clear();
69
70         resources.add(new ResourceBuilder().setResource(tpIn).build());
71         ids.add(tpIn.getTerminationPointIdentifier().getNodeId().concat("-")
72                 .concat(tpIn.getTerminationPointIdentifier().getTpId()));
73         resources.add(new ResourceBuilder().setResource(node).build());
74         ids.add(node.getNodeIdentifier().getNodeId());
75         resources.add(new ResourceBuilder().setResource(tpOut).build());
76         ids.add(tpOut.getTerminationPointIdentifier().getNodeId().concat("-")
77                 .concat(tpOut.getTerminationPointIdentifier().getTpId()));
78     }
79
80     /**
81      * Create an hop in AtoZList.
82      * @param odr hop number
83      */
84     public void createAToZListHop(int odr) {
85         AToZ hop = null;
86         AToZKey atozKey = null;
87         createListResource();
88         for (Resource resource : resources) {
89             atozKey = new AToZKey(Integer.toString(odr));
90             resource = new ResourceBuilder().setResource(resource.getResource()).build();
91             hop = new AToZBuilder()
92                     .setKey(atozKey)
93                     .setResource(resource)
94                     .build();
95             atoz.add(hop);
96             odr++;
97         }
98     }
99
100     /**
101      * Create an hop in ZtoAList.
102      * @param odr hop number
103      */
104     public void createZToAListHop(int odr) {
105         ZToA hop = null;
106         ZToAKey ztoaKey = null;
107         createListResource();
108         for (Resource resource : resources) {
109             ztoaKey = new ZToAKey(Integer.toString(odr));
110             resource = new ResourceBuilder().setResource(resource.getResource()).build();
111             hop = new ZToABuilder()
112                     .setKey(ztoaKey)
113                     .setResource(resource)
114                     .build();
115             ztoa.add(hop);
116             odr++;
117         }
118     }
119
120     public TpNodeTp reverse() {
121         return new TpNodeTp(tpOut, tpIn, node);
122     }
123
124     @Override
125     public String toString() {
126         StringBuilder result = new StringBuilder("[ ");
127         result.append("tpIn : " + tpIn.getTerminationPointIdentifier().getTpId());
128         result.append(" - Node : " + node.getNodeIdentifier().getNodeId());
129         result.append(" - tpOut : " + tpOut.getTerminationPointIdentifier().getTpId());
130         result.append(" ]");
131         return result.toString();
132
133     }
134
135     public List<AToZ> getAToZ() {
136         return atoz;
137     }
138
139     public List<ZToA> getZToA() {
140         return ztoa;
141     }
142
143     public Node getNode() {
144         return node;
145     }
146
147     public TerminationPoint getTpIn() {
148         return tpIn;
149     }
150
151     public TerminationPoint getTpOut() {
152         return tpOut;
153     }
154 }