Merge "ROADM To ROADM Path Calculation"
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmInterfaceFactory.java
1 /*
2  * Copyright © 2017 AT&T 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.renderer.openroadminterface;
10
11 import java.math.BigDecimal;
12 import org.opendaylight.transportpce.common.mapping.PortMapping;
13 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
14 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
15 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.Mapping;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.PowerDBm;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev161014.AdminStates;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.EthAttributes;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.Interface1Builder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev161014.ethernet.container.EthernetBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.EthernetCsmacd;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpenROADMOpticalMultiplex;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpticalChannel;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpticalTransport;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OtnOdu;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OtnOtu;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.OchAttributes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.RateIdentity;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.och.container.OchBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.OtsAttributes.FiberType;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.ots.container.OtsBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.ODU4;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.OduAttributes;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.odu.container.OduBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.opu.OpuBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.OTU4;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.OtuAttributes;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.otu.container.OtuBuilder;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 public class OpenRoadmInterfaceFactory {
48     private final PortMapping portMapping;
49     private final OpenRoadmInterfaces openRoadmInterfaces;
50     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfaceFactory.class);
51
52     public OpenRoadmInterfaceFactory(PortMapping portMapping, OpenRoadmInterfaces openRoadmInterfaces) {
53         this.portMapping = portMapping;
54         this.openRoadmInterfaces = openRoadmInterfaces;
55     }
56
57     public String createOpenRoadmEthInterface(String nodeId, String logicalConnPoint)
58         throws OpenRoadmInterfaceException {
59         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
60         if (portMap == null) {
61             throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node % and"
62                 + " logical connection port %s", nodeId, logicalConnPoint));
63         }
64
65         // Ethernet interface specific data
66         EthernetBuilder ethIfBuilder = new EthernetBuilder();
67         ethIfBuilder.setAutoNegotiation(EthAttributes.AutoNegotiation.Enabled);
68         ethIfBuilder.setDuplex(EthAttributes.Duplex.Full);
69         ethIfBuilder.setFec(EthAttributes.Fec.Off);
70         ethIfBuilder.setSpeed(100000L);
71         ethIfBuilder.setMtu(9000L);
72
73         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.class,
74             logicalConnPoint + "-ETHERNET");
75
76         // Create Interface1 type object required for adding as augmentation
77         Interface1Builder ethIf1Builder = new Interface1Builder();
78         ethInterfaceBldr.addAugmentation(Interface1.class, ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
79
80         // Post interface on the device
81         this.openRoadmInterfaces.postInterface(nodeId, ethInterfaceBldr);
82
83         // Post the equipment-state change on the device circuit-pack
84         this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
85
86         return ethInterfaceBldr.getName();
87     }
88
89     /**
90      * This methods creates an OCH interface on the given termination point on
91      * Roadm.
92      *
93      * @param nodeId node ID
94      * @param logicalConnPoint logical Connection Point
95      * @param waveNumber wavelength number of the OCH interface
96      *
97      * @return Name of the interface if successful, otherwise return null.
98      * @throws OpenRoadmInterfaceException OpenRoadmInterfaceException
99      */
100
101     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber)
102         throws OpenRoadmInterfaceException {
103         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
104         if (portMap == null) {
105             throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node %s and"
106                 + " logical connection port %s", nodeId, logicalConnPoint));
107         }
108         // Create generic interface
109         InterfaceBuilder ochInterfaceBldr = createGenericInterfaceBuilder(portMap, OpticalChannel.class,
110             createOpenRoadmOchInterfaceName(logicalConnPoint, waveNumber));
111
112         // OCH interface specific data
113         OchBuilder ocIfBuilder = new OchBuilder();
114         ocIfBuilder.setWavelengthNumber(waveNumber);
115
116         // Add supporting OMS interface
117         if (portMap.getSupportingOms() != null) {
118             ochInterfaceBldr.setSupportingInterface(portMap.getSupportingOms());
119         }
120         // Create Interface1 type object required for adding as augmentation
121         // TODO look at imports of different versions of class
122         org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014
123             .Interface1Builder ochIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel
124             .interfaces.rev161014.Interface1Builder();
125         ochInterfaceBldr.addAugmentation(
126             org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class,
127             ochIf1Builder.setOch(ocIfBuilder.build()).build());
128
129         // Post interface on the device
130         this.openRoadmInterfaces.postInterface(nodeId, ochInterfaceBldr);
131
132         // Post the equipment-state change on the device circuit-pack if xpdr node
133         if (portMap.getLogicalConnectionPoint().contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
134             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
135         }
136         return ochInterfaceBldr.getName();
137     }
138
139     public String createOpenRoadmOchInterface(String nodeId, String logicalConnPoint, Long waveNumber, Class<
140         ? extends RateIdentity> rate, OchAttributes.ModulationFormat format) throws OpenRoadmInterfaceException {
141         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
142         if (portMap == null) {
143             throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node %s and"
144                 + " logical connection port %s", nodeId, logicalConnPoint));
145         }
146
147         // OCH interface specific data
148         OchBuilder ocIfBuilder = new OchBuilder();
149         ocIfBuilder.setWavelengthNumber(waveNumber);
150         ocIfBuilder.setModulationFormat(format);
151         ocIfBuilder.setRate(rate);
152         ocIfBuilder.setTransmitPower(new PowerDBm(new BigDecimal("-5")));
153
154         // Create Interface1 type object required for adding as augmentation
155         // TODO look at imports of different versions of class
156         org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014
157             .Interface1Builder ochIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel
158             .interfaces.rev161014.Interface1Builder();
159         // Create generic interface
160         InterfaceBuilder ochInterfaceBldr = createGenericInterfaceBuilder(portMap, OpticalChannel.class,
161             createOpenRoadmOchInterfaceName(logicalConnPoint, waveNumber));
162         ochInterfaceBldr.addAugmentation(
163             org.opendaylight.yang.gen.v1.http.org.openroadm.optical.channel.interfaces.rev161014.Interface1.class,
164             ochIf1Builder.setOch(ocIfBuilder.build()).build());
165
166         // Post interface on the device
167         this.openRoadmInterfaces.postInterface(nodeId, ochInterfaceBldr);
168
169         // Post the equipment-state change on the device circuit-pack if xpdr node
170         if (portMap.getLogicalConnectionPoint().contains(OpenRoadmInterfacesImpl.NETWORK_TOKEN)) {
171             this.openRoadmInterfaces.postEquipmentState(nodeId, portMap.getSupportingCircuitPackName(), true);
172         }
173         return ochInterfaceBldr.getName();
174     }
175
176     public String createOpenRoadmOchInterfaceName(String logicalConnectionPoint, Long waveNumber) {
177         return logicalConnectionPoint + "-" + waveNumber;
178     }
179
180     /**
181      * This methods creates an ODU interface on the given termination point.
182      *
183      * @param nodeId node ID
184      * @param logicalConnPoint logical Connection Point
185      * @param supportingOtuInterface supporting OTU Interface
186      *
187      * @return Name of the interface if successful, otherwise return null.
188      * @throws OpenRoadmInterfaceException OpenRoadmInterfaceException
189      */
190
191     public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint, String supportingOtuInterface)
192         throws OpenRoadmInterfaceException {
193         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
194         if (portMap == null) {
195             throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node % and"
196                 + " logical connection port %s", nodeId, logicalConnPoint));
197         }
198         InterfaceBuilder oduInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOdu.class, logicalConnPoint
199             + "-ODU");
200         oduInterfaceBldr.setSupportingInterface(supportingOtuInterface);
201
202         // ODU interface specific data
203         OduBuilder oduIfBuilder = new OduBuilder();
204         oduIfBuilder.setRate(ODU4.class);
205         oduIfBuilder.setMonitoringMode(OduAttributes.MonitoringMode.Terminated);
206
207         // Set Opu attributes
208         OpuBuilder opuBldr = new OpuBuilder();
209         opuBldr.setPayloadType("07");
210         opuBldr.setExpPayloadType("07");
211         oduIfBuilder.setOpu(opuBldr.build());
212
213         // Create Interface1 type object required for adding as augmentation
214         // TODO look at imports of different versions of class
215         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1Builder oduIf1Builder =
216             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1Builder();
217         oduInterfaceBldr.addAugmentation(
218             org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev161014.Interface1.class, oduIf1Builder
219                 .setOdu(oduIfBuilder.build()).build());
220
221         // Post interface on the device
222         this.openRoadmInterfaces.postInterface(nodeId, oduInterfaceBldr);
223         return oduInterfaceBldr.getName();
224     }
225
226     /**
227      * This methods creates an OTU interface on the given termination point.
228      *
229      * @param nodeId node ID
230      * @param logicalConnPoint logical Connection Point
231      * @param supportOchInterface support OCH Interface
232      *
233      * @return Name of the interface if successful, otherwise return null.
234      * @throws OpenRoadmInterfaceException OpenRoadmInterfaceException
235      */
236
237     public String createOpenRoadmOtu4Interface(String nodeId, String logicalConnPoint, String supportOchInterface)
238         throws OpenRoadmInterfaceException {
239         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
240         if (portMap == null) {
241             throw new OpenRoadmInterfaceException(String.format("Unable to get mapping from PortMapping for node % and"
242                 + " logical connection port %s", nodeId, logicalConnPoint));
243         }
244         // Create generic interface
245         InterfaceBuilder otuInterfaceBldr = createGenericInterfaceBuilder(portMap, OtnOtu.class, logicalConnPoint
246             + "-OTU");
247         otuInterfaceBldr.setSupportingInterface(supportOchInterface);
248
249         // OTU interface specific data
250         OtuBuilder otuIfBuilder = new OtuBuilder();
251         otuIfBuilder.setFec(OtuAttributes.Fec.Scfec);
252         otuIfBuilder.setRate(OTU4.class);
253
254         // Create Interface1 type object required for adding as augmentation
255         // TODO look at imports of different versions of class
256         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1Builder otuIf1Builder =
257             new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1Builder();
258         otuInterfaceBldr.addAugmentation(
259             org.opendaylight.yang.gen.v1.http.org.openroadm.otn.otu.interfaces.rev161014.Interface1.class, otuIf1Builder
260                 .setOtu(otuIfBuilder.build()).build());
261
262         // Post interface on the device
263         this.openRoadmInterfaces.postInterface(nodeId, otuInterfaceBldr);
264         return otuInterfaceBldr.getName();
265     }
266
267     public String createOpenRoadmOtsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
268         if (mapping.getSupportingOts() == null) {
269             // Create generic interface
270             InterfaceBuilder otsInterfaceBldr = createGenericInterfaceBuilder(mapping, OpticalTransport.class, "OTS-"
271                 + mapping.getLogicalConnectionPoint());
272             // OTS interface augmentation specific data
273             OtsBuilder otsIfBuilder = new OtsBuilder();
274             otsIfBuilder.setFiberType(FiberType.Smf);
275
276             // Create Interface1 type object required for adding as
277             // augmentation
278             org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014
279                 .Interface1Builder otsIf1Builder = new org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport
280                 .interfaces.rev161014.Interface1Builder();
281             otsInterfaceBldr.addAugmentation(
282                 org.opendaylight.yang.gen.v1.http.org.openroadm.optical.transport.interfaces.rev161014.Interface1.class,
283                 otsIf1Builder.setOts(otsIfBuilder.build()).build());
284             this.openRoadmInterfaces.postInterface(nodeId, otsInterfaceBldr);
285             this.portMapping.updateMapping(nodeId, mapping);
286             return otsInterfaceBldr.build().getName();
287         } else {
288             return mapping.getSupportingOts();
289         }
290     }
291
292     public String createOpenRoadmOmsInterface(String nodeId, Mapping mapping) throws OpenRoadmInterfaceException {
293         if (mapping.getSupportingOms() == null) {
294             // Create generic interface
295             InterfaceBuilder omsInterfaceBldr = createGenericInterfaceBuilder(mapping, OpenROADMOpticalMultiplex.class,
296                 "OMS-" + mapping.getLogicalConnectionPoint());
297             if (mapping.getSupportingOts() != null) {
298                 omsInterfaceBldr.setSupportingInterface(mapping.getSupportingOts());
299             } else {
300                 LOG.error("Unable to get ots interface from mapping {} - {}", nodeId,
301                         mapping.getLogicalConnectionPoint());
302                 return null;
303             }
304             this.openRoadmInterfaces.postInterface(nodeId, omsInterfaceBldr);
305             this.portMapping.updateMapping(nodeId, mapping);
306             return omsInterfaceBldr.build().getName();
307         } else {
308             return mapping.getSupportingOms();
309         }
310     }
311
312     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, Class<? extends InterfaceType> type,
313         String key) {
314         InterfaceBuilder interfaceBuilder = new InterfaceBuilder();
315         interfaceBuilder.setDescription("  TBD   ");
316         interfaceBuilder.setCircuitId("   TBD    ");
317         interfaceBuilder.setSupportingCircuitPackName(portMap.getSupportingCircuitPackName());
318         interfaceBuilder.setSupportingPort(portMap.getSupportingPort());
319         interfaceBuilder.setAdministrativeState(AdminStates.InService);
320         interfaceBuilder.setType(type);
321         interfaceBuilder.setName(key);
322         interfaceBuilder.withKey(new InterfaceKey(key));
323         return interfaceBuilder;
324     }
325 }