TAPI topology creation for 100GE Transponder
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / utils / TapiUtils.java
1 /*
2  * Copyright © 2018 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 package org.opendaylight.transportpce.tapi.utils;
9
10 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.equipment.types.rev181130.OpticTypes;
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.RpcActions;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.RxDirectionBuilder;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.endpoint.TxDirectionBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.lgx.LgxBuilder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.port.PortBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInputBuilder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEnd;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceAEndBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEnd;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.create.input.ServiceZEndBuilder;
26
27 public final class TapiUtils {
28
29     private TapiUtils() {
30     }
31
32     public static ServiceCreateInput buildServiceCreateInput(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
33         ServiceCreateInputBuilder builtInput = new ServiceCreateInputBuilder();
34         ServiceAEnd serviceAEnd = getServiceAEnd(sepA, sepZ);
35         ServiceZEnd serviceZEnd = getServiceZEnd(sepA, sepZ);
36         if (serviceAEnd != null && serviceZEnd != null) {
37             builtInput.setCommonId("commonId");
38             builtInput.setConnectionType(ConnectionType.Service);
39             builtInput.setCustomer("Customer");
40             builtInput.setServiceName("service test");
41             builtInput.setServiceAEnd(serviceAEnd);
42             builtInput.setServiceZEnd(serviceZEnd);
43             builtInput.setSdncRequestHeader(new SdncRequestHeaderBuilder().setRequestId("request-1")
44                 .setRpcAction(RpcActions.ServiceCreate).setNotificationUrl("notification url").setRequestSystemId(
45                     "appname")
46                 .build());
47         } else {
48             return null;
49         }
50         return builtInput.build();
51     }
52
53     public static ServiceAEnd buildServiceAEnd(String nodeid, String clli, String txPortDeviceName,
54         String txPortName, String rxPortDeviceName, String rxPortName) {
55         ServiceAEnd serviceAEnd = new ServiceAEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid)).setOpticType(
56             OpticTypes.Gray).setServiceFormat(
57                 ServiceFormat.Ethernet).setServiceRate(new Long(100))
58             .setTxDirection(
59                 new TxDirectionBuilder()
60                     .setPort(new PortBuilder().setPortDeviceName(txPortDeviceName).setPortName(txPortName)
61                         .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
62                     .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
63                         "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build())
64                     .build())
65             .setRxDirection(
66                 new RxDirectionBuilder()
67                     .setPort(new PortBuilder().setPortDeviceName(rxPortDeviceName).setPortName(rxPortName)
68                         .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
69                     .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
70                         "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build()).build())
71             .build();
72         return serviceAEnd;
73     }
74
75     public static ServiceZEnd buildServiceZEnd(String nodeid, String clli, String txPortDeviceName,
76         String txPortName, String rxPortDeviceName, String rxPortName) {
77         ServiceZEnd serviceZEnd = new ServiceZEndBuilder().setClli(clli).setNodeId(new NodeIdType(nodeid)).setOpticType(
78             OpticTypes.Gray).setServiceFormat(
79                 ServiceFormat.Ethernet).setServiceRate(new Long(100))
80             .setTxDirection(
81                 new TxDirectionBuilder()
82                     .setPort(new PortBuilder().setPortDeviceName(txPortDeviceName).setPortName(txPortName)
83                         .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
84                     .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
85                         "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build())
86                     .build())
87             .setRxDirection(
88                 new RxDirectionBuilder()
89                     .setPort(new PortBuilder().setPortDeviceName(rxPortDeviceName).setPortName(rxPortName)
90                         .setPortRack("000000.00").setPortShelf("00").setPortType("some port type").build())
91                     .setLgx(new LgxBuilder().setLgxDeviceName("Some lgx-device-name").setLgxPortName(
92                         "Some lgx-port-name").setLgxPortRack("000000.00").setLgxPortShelf("00").build()).build())
93             .build();
94         return serviceZEnd;
95     }
96
97     private static ServiceAEnd getServiceAEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
98         if (sepA.getType().equals(ServiceEndpointType.SERVICEAEND)) {
99             return new ServiceAEndBuilder(sepA.getValue()).build();
100         } else if (sepZ.getType().equals(ServiceEndpointType.SERVICEAEND)) {
101             return new ServiceAEndBuilder(sepZ.getValue()).build();
102         } else {
103             return null;
104         }
105     }
106
107     private static ServiceZEnd getServiceZEnd(GenericServiceEndpoint sepA, GenericServiceEndpoint sepZ) {
108         if (sepA.getType().equals(ServiceEndpointType.SERVICEZEND)) {
109             return new ServiceZEndBuilder(sepA.getValue()).build();
110         } else if (sepZ.getType().equals(ServiceEndpointType.SERVICEZEND)) {
111             return new ServiceZEndBuilder(sepZ.getValue()).build();
112         } else {
113             return null;
114         }
115     }
116 }