Stubpce Update
[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.getTpNodeId().concat("-").concat(tpIn.getTpId()));
72         resources.add(new ResourceBuilder().setResource(node).build());
73         ids.add(node.getNodeId());
74         resources.add(new ResourceBuilder().setResource(tpOut).build());
75         ids.add(tpOut.getTpNodeId().concat("-").concat(tpOut.getTpId()));
76     }
77
78     /**
79      * Create an hop in AtoZList.
80      * @param odr hop number
81      */
82     public void createAToZListHop(int odr) {
83         AToZ hop = null;
84         AToZKey atozKey = null;
85         createListResource();
86         for (Resource resource : resources) {
87             atozKey = new AToZKey(Integer.toString(odr));
88             resource = new ResourceBuilder().setResource(resource.getResource()).build();
89             hop = new AToZBuilder()
90                     .setKey(atozKey)
91                     .setResource(resource)
92                     .build();
93             atoz.add(hop);
94             odr++;
95         }
96     }
97
98     /**
99      * Create an hop in ZtoAList.
100      * @param odr hop number
101      */
102     public void createZToAListHop(int odr) {
103         ZToA hop = null;
104         ZToAKey ztoaKey = null;
105         createListResource();
106         for (Resource resource : resources) {
107             ztoaKey = new ZToAKey(Integer.toString(odr));
108             resource = new ResourceBuilder().setResource(resource.getResource()).build();
109             hop = new ZToABuilder()
110                     .setKey(ztoaKey)
111                     .setResource(resource)
112                     .build();
113             ztoa.add(hop);
114             odr++;
115         }
116     }
117
118     public TpNodeTp reverse() {
119         return new TpNodeTp(tpOut, tpIn, node);
120     }
121
122     @Override
123     public String toString() {
124         StringBuilder result = new StringBuilder("[ ");
125         result.append("tpIn : " + tpIn.getTpId());
126         result.append(" - Node : " + node.getNodeId());
127         result.append(" - tpOut : " + tpOut.getTpId());
128         result.append(" ]");
129         return result.toString();
130
131     }
132
133     public List<AToZ> getAToZ() {
134         return atoz;
135     }
136
137     public List<ZToA> getZToA() {
138         return ztoa;
139     }
140
141     public Node getNode() {
142         return node;
143     }
144
145     public TerminationPoint getTpIn() {
146         return tpIn;
147     }
148
149     public TerminationPoint getTpOut() {
150         return tpOut;
151     }
152 }