Add allure-pytest tox profiles for local use
[transportpce.git] / renderer / src / main / java / org / opendaylight / transportpce / renderer / openroadminterface / OpenRoadmOtnInterface710.java
1 /*
2  * Copyright © 2021 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 package org.opendaylight.transportpce.renderer.openroadminterface;
9
10 import java.util.HashSet;
11 import java.util.Set;
12 import java.util.stream.IntStream;
13 import org.opendaylight.transportpce.common.mapping.PortMapping;
14 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
15 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
16 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.parent.odu.allocation.ParentOduAllocationBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.attributes.rev200327.parent.odu.allocation.parent.odu.allocation.trib.slots.choice.OpucnBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev200529.Off;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.interfaces.grp.InterfaceKey;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.Interface1Builder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.ethernet.interfaces.rev200529.ethernet.container.EthernetBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.EthernetCsmacd;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.InterfaceType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnOdu;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU4;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUCTP;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODUTTPCTP;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.PayloadTypeDef;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.OpucnTribSlotDef;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.OduAttributes.MonitoringMode;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.odu.container.OduBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.opu.OpuBuilder;
36 import org.opendaylight.yangtools.yang.common.Uint16;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class OpenRoadmOtnInterface710 {
42     private final PortMapping portMapping;
43     private final OpenRoadmInterfaces openRoadmInterfaces;
44     private static final Logger LOG = LoggerFactory
45         .getLogger(OpenRoadmOtnInterface710.class);
46
47     public OpenRoadmOtnInterface710(PortMapping portMapping,
48         OpenRoadmInterfaces openRoadmInterfaces) {
49         this.portMapping = portMapping;
50         this.openRoadmInterfaces = openRoadmInterfaces;
51     }
52
53     public String createOpenRoadmEth100GInterface(String nodeId,
54         String logicalConnPoint) throws OpenRoadmInterfaceException {
55
56         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
57         if (portMap == null) {
58             throwException(nodeId, logicalConnPoint);
59         }
60
61         // Ethernet interface specific data
62         EthernetBuilder ethIfBuilder = new EthernetBuilder()
63             .setFec(Off.VALUE)
64             .setSpeed(Uint32.valueOf(100000));
65         InterfaceBuilder ethInterfaceBldr = createGenericInterfaceBuilder(portMap, EthernetCsmacd.VALUE,
66             logicalConnPoint + "-ETHERNET-100G");
67         // Create Interface1 type object required for adding as augmentation
68         Interface1Builder ethIf1Builder = new Interface1Builder();
69         ethInterfaceBldr.addAugmentation(ethIf1Builder.setEthernet(ethIfBuilder.build()).build());
70         // Post interface on the device
71         this.openRoadmInterfaces.postOTNInterface(nodeId, ethInterfaceBldr);
72         // Post the equipment-state change on the device circuit-pack
73         this.openRoadmInterfaces.postOTNEquipmentState(nodeId,
74             portMap.getSupportingCircuitPackName(), true);
75         this.portMapping.updateMapping(nodeId, portMap);
76         String ethernetInterfaceName = ethInterfaceBldr.getName();
77
78         return ethernetInterfaceName;
79     }
80
81     private void throwException(String nodeId, String logicalConnPoint)
82         throws OpenRoadmInterfaceException {
83
84         throw new OpenRoadmInterfaceException(String.format(
85             "Unable to get mapping from PortMapping for node % and logical connection port %s",
86             nodeId, logicalConnPoint));
87     }
88
89     public String createOpenRoadmOdu4Interface(String nodeId, String logicalConnPoint,
90         String payLoad, boolean isNetworkPort, OpucnTribSlotDef minTribSlotNumber, OpucnTribSlotDef maxTribSlotNumber)
91         throws OpenRoadmInterfaceException {
92         Mapping portMap = this.portMapping.getMapping(nodeId, logicalConnPoint);
93         if (portMap == null) {
94             throwException(nodeId, logicalConnPoint);
95         }
96         Set<String> supportingInterfaceList = new HashSet<>();
97         String supportingInterface = null;
98         if (isNetworkPort) {
99             supportingInterface = portMap.getSupportingOducn();
100             // TODO: remove this log
101             LOG.info("ODUCn supporting interface on port mapping {}", supportingInterface);
102         } else {
103             supportingInterface = logicalConnPoint + "-ETHERNET-100G";
104         }
105
106         if (supportingInterface == null) {
107             throw new OpenRoadmInterfaceException(
108                 "Interface Creation failed because of missing supported "
109                     + "ODU4 on network end or Ethernet on client");
110         }
111         // Supporting interface is a list for B100G (7.1) device models
112         supportingInterfaceList.add(supportingInterface);
113
114         InterfaceBuilder oduIfBuilder = createGenericInterfaceBuilder(portMap, OtnOdu.VALUE, logicalConnPoint + "-ODU4")
115             .setSupportingInterfaceList(supportingInterfaceList);
116         // Agument ODU4 specific interface data
117         OduBuilder oduBuilder = new OduBuilder().setRate(ODU4.VALUE)
118             .setOduFunction(ODUTTPCTP.VALUE)
119             .setMonitoringMode(MonitoringMode.Terminated);
120         LOG.debug("Inside the ODU4 creation {} {} {}", isNetworkPort, minTribSlotNumber.getValue(),
121             maxTribSlotNumber.getValue());
122         // If it is a network port we have fill the required trib-slots and trib-ports
123         if (isNetworkPort) {
124             Set<org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef>
125                 opucnTribSlotDefList = new HashSet<>();
126             // Escape characters are used to here to take the literal dot
127             Uint16 tribPortNumber = Uint16.valueOf(minTribSlotNumber.getValue().split("\\.")[0]);
128             Uint16 startTribSlot = Uint16.valueOf(minTribSlotNumber.getValue().split("\\.")[1]);
129             Uint16 endTribSlot = Uint16.valueOf(maxTribSlotNumber.getValue().split("\\.")[1]);
130
131             IntStream.range(startTribSlot.intValue(), endTribSlot.intValue() + 1)
132                 .forEach(nbr -> opucnTribSlotDefList.add(
133                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef
134                     .getDefaultInstance(tribPortNumber + "." + nbr))
135                 );
136             ParentOduAllocationBuilder parentOduAllocationBuilder = new ParentOduAllocationBuilder()
137                 .setTribPortNumber(tribPortNumber)
138                 .setTribSlotsChoice(new OpucnBuilder().setOpucnTribSlots(opucnTribSlotDefList).build());
139             // reset the ODU function as ODUCTP and the monitoring moode
140             oduBuilder.setOduFunction(ODUCTP.VALUE)
141                 .setMonitoringMode(MonitoringMode.NotTerminated)
142                 .setParentOduAllocation(parentOduAllocationBuilder.build());
143         }
144         else {
145            //  This is for the client side of the ODU (ODU-TTP-CTP)
146             // Set Opu attributes
147             OpuBuilder opuBuilder = new OpuBuilder()
148                 .setExpPayloadType(new PayloadTypeDef(payLoad))
149                 .setPayloadType(new PayloadTypeDef(payLoad));
150             oduBuilder.setOpu(opuBuilder.build());
151         }
152
153         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder
154             oduIf1Builder = new
155             org.opendaylight.yang.gen.v1.http.org.openroadm.otn.odu.interfaces.rev200529.Interface1Builder();
156         oduIfBuilder.addAugmentation(oduIf1Builder.setOdu(oduBuilder.build()).build());
157         // Post interface on the device
158         this.openRoadmInterfaces.postOTNInterface(nodeId, oduIfBuilder);
159         LOG.info("Returning the ODU4 inteface {}", oduIfBuilder.getName());
160         return oduIfBuilder.getName();
161     }
162
163     private InterfaceBuilder createGenericInterfaceBuilder(Mapping portMap, InterfaceType type, String key) {
164         return new InterfaceBuilder()
165             // .setDescription(" TBD ")
166             // .setCircuitId(" TBD ")
167             .setSupportingCircuitPackName(
168                 portMap.getSupportingCircuitPackName())
169             .setSupportingPort(portMap.getSupportingPort())
170             .setAdministrativeState(AdminStates.InService)
171             // TODO get rid of unchecked cast warning
172             .setType(type).setName(key).withKey(new InterfaceKey(key));
173     }
174 }