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