2 * Copyright © 2020 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.nbinotifications.utils;
10 import java.nio.charset.Charset;
11 import java.time.OffsetDateTime;
12 import java.time.ZoneOffset;
13 import java.time.format.DateTimeFormatter;
14 import java.util.HashMap;
15 import java.util.HashSet;
16 import java.util.List;
18 import java.util.UUID;
19 import java.util.concurrent.ExecutionException;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirection;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirectionBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.RxDirectionKey;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirection;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionKey;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.lgx.LgxBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.port.PortBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
34 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessService;
35 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.NotificationProcessServiceBuilder;
36 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.alarm.service.output.NotificationsAlarmService;
37 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.alarm.service.output.NotificationsAlarmServiceBuilder;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.process.service.output.NotificationsProcessService;
39 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.get.notifications.process.service.output.NotificationsProcessServiceBuilder;
40 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.process.service.ServiceAEndBuilder;
41 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230728.notification.process.service.ServiceZEndBuilder;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.AdministrativeState;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Context;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.ContextBuilder;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.DateAndTime;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OBJECTTYPETAPICONTEXT;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OperationalState;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.Name;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.local._class.NameBuilder;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.Context1;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.Context1Builder;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.context.ConnectivityContextBuilder;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.CreateNotificationSubscriptionServiceInputBuilder;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.GetNotificationListInputBuilder;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.NOTIFICATIONTYPEATTRIBUTEVALUECHANGE;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.NOTIFICATIONTYPEOBJECTCREATION;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.NOTIFICATIONTYPEOBJECTDELETION;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.SubscriptionState;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.context.NotificationContextBuilder;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.create.notification.subscription.service.input.SubscriptionFilter;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.create.notification.subscription.service.input.SubscriptionFilterBuilder;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.list.output.Notification;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.get.notification.list.output.NotificationBuilder;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.ChangedAttributes;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.ChangedAttributesBuilder;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.TargetObjectName;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.notification.TargetObjectNameBuilder;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.context.TopologyContextBuilder;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.NwTopologyServiceBuilder;
72 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
73 import org.opendaylight.yangtools.yang.common.Uint32;
74 import org.opendaylight.yangtools.yang.common.Uint8;
76 public final class NotificationServiceDataUtils {
78 public static final String TAPI_CONTEXT = "T-API context";
80 private NotificationServiceDataUtils() {
83 public static NotificationProcessService buildSendEventInput() {
84 return new NotificationProcessServiceBuilder()
85 .setMessage("message")
86 .setServiceName("service1")
87 .setOperationalState(State.InService)
88 .setResponseFailed("")
89 .setCommonId("commond-id")
90 .setConnectionType(ConnectionType.Service)
91 .setServiceZEnd(getServiceZEndBuild().build())
92 .setServiceAEnd(getServiceAEndBuild().build())
96 public static NotificationsProcessService buildReceivedEvent() {
97 return new NotificationsProcessServiceBuilder()
98 .setMessage("message")
99 .setServiceName("service1")
100 .setOperationalState(State.InService)
101 .setResponseFailed("")
102 .setCommonId("commond-id")
103 .setConnectionType(ConnectionType.Service)
104 .setServiceZEnd(getServiceZEndBuild().build())
105 .setServiceAEnd(getServiceAEndBuild().build())
109 public static NotificationsAlarmService buildReceivedAlarmEvent() {
110 return new NotificationsAlarmServiceBuilder()
111 .setMessage("message")
112 .setServiceName("service1")
113 .setOperationalState(State.InService)
114 .setConnectionType(ConnectionType.Service)
118 public static Notification buildReceivedTapiAlarmEvent() {
119 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
120 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
121 DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
122 Uuid targetObjectId = new Uuid(UUID.randomUUID().toString());
123 TargetObjectName objectName = new TargetObjectNameBuilder()
124 .setValue(targetObjectId.getValue())
125 .setValueName("Connectivity Service Name")
127 ChangedAttributes adminStateChange = new ChangedAttributesBuilder()
128 .setValueName("administrativeState")
129 .setOldValue(AdministrativeState.LOCKED.getName())
130 .setNewValue(AdministrativeState.UNLOCKED.getName())
132 ChangedAttributes operStateChange = new ChangedAttributesBuilder()
133 .setValueName("operationalState")
134 .setOldValue(OperationalState.DISABLED.getName())
135 .setNewValue(OperationalState.ENABLED.getName())
137 return new NotificationBuilder()
138 .setNotificationType(NOTIFICATIONTYPEATTRIBUTEVALUECHANGE.VALUE)
139 .setLayerProtocolName(LayerProtocolName.ETH)
140 .setTargetObjectType(OBJECTTYPETAPICONTEXT.VALUE)
141 .setEventTimeStamp(datetime)
142 .setUuid(new Uuid(UUID.randomUUID().toString()))
143 .setTargetObjectIdentifier(targetObjectId)
144 .setTargetObjectName(Map.of(objectName.key(), objectName))
145 .setChangedAttributes(Map.of(adminStateChange.key(), adminStateChange,
146 operStateChange.key(), operStateChange))
150 public static ServiceAEndBuilder getServiceAEndBuild() {
151 return new ServiceAEndBuilder()
153 .setServiceFormat(ServiceFormat.OC)
154 .setServiceRate(Uint32.valueOf(1))
155 .setNodeId(new NodeIdType("XPONDER-1-2"))
156 .setTxDirection(getTxDirection())
157 .setRxDirection(getRxDirection());
160 public static ServiceZEndBuilder getServiceZEndBuild() {
161 return new ServiceZEndBuilder()
163 .setServiceFormat(ServiceFormat.OC)
164 .setServiceRate(Uint32.valueOf(1))
165 .setNodeId(new NodeIdType("XPONDER-1-2"))
166 .setTxDirection(getTxDirection())
167 .setRxDirection(getRxDirection());
170 public static CreateNotificationSubscriptionServiceInputBuilder buildNotificationSubscriptionServiceInputBuilder() {
171 Name name = new NameBuilder()
172 .setValue("test subscription")
173 .setValueName("Subscription name")
175 SubscriptionFilter subscriptionFilter = new SubscriptionFilterBuilder()
176 .setRequestedObjectTypes(new HashSet<>(List.of(OBJECTTYPETAPICONTEXT.VALUE)))
177 .setRequestedNotificationTypes(new HashSet<>(List.of(NOTIFICATIONTYPEATTRIBUTEVALUECHANGE.VALUE,
178 NOTIFICATIONTYPEOBJECTCREATION.VALUE, NOTIFICATIONTYPEOBJECTDELETION.VALUE)))
179 .setRequestedLayerProtocols(new HashSet<>(List.of(LayerProtocolName.ETH)))
180 .setRequestedObjectIdentifier(new HashSet<>(List.of(new Uuid(UUID.randomUUID().toString()))))
181 .setIncludeContent(true)
182 .setLocalId("localId")
183 .setName(Map.of(name.key(), name))
185 return new CreateNotificationSubscriptionServiceInputBuilder()
186 .setSubscriptionFilter(subscriptionFilter)
187 .setSubscriptionState(SubscriptionState.ACTIVE);
190 private static Map<TxDirectionKey, TxDirection> getTxDirection() {
191 return Map.of(new TxDirectionKey(Uint8.ZERO), new TxDirectionBuilder()
192 .setPort(new PortBuilder()
193 .setPortDeviceName("device name")
194 .setPortName("port name")
195 .setPortRack("port rack")
196 .setPortShelf("port shelf")
197 .setPortSlot("port slot")
198 .setPortSubSlot("port subslot")
199 .setPortType("port type")
201 .setLgx(new LgxBuilder()
202 .setLgxDeviceName("lgx device name")
203 .setLgxPortName("lgx port name")
204 .setLgxPortRack("lgx port rack")
205 .setLgxPortShelf("lgx port shelf")
207 .setIndex(Uint8.ZERO)
211 private static Map<RxDirectionKey, RxDirection> getRxDirection() {
212 return Map.of(new RxDirectionKey(Uint8.ZERO), new RxDirectionBuilder()
213 .setPort(new PortBuilder()
214 .setPortDeviceName("device name")
215 .setPortName("port name")
216 .setPortRack("port rack")
217 .setPortShelf("port shelf")
218 .setPortSlot("port slot")
219 .setPortSubSlot("port subslot")
220 .setPortType("port type")
222 .setLgx(new LgxBuilder()
223 .setLgxDeviceName("lgx device name")
224 .setLgxPortName("lgx port name")
225 .setLgxPortRack("lgx port rack")
226 .setLgxPortShelf("lgx port shelf")
228 .setIndex(Uint8.ZERO)
232 public static void createTapiContext(
233 NetworkTransactionService networkTransactionService) throws ExecutionException, InterruptedException {
234 // Augmenting tapi context to include topology and connectivity contexts
235 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name contextName
236 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder()
237 .setValue(TAPI_CONTEXT).setValueName("TAPI Context Name").build();
239 Context1 connectivityContext =
240 new Context1Builder()
241 .setConnectivityContext(
242 new ConnectivityContextBuilder()
243 .setConnection(new HashMap<>())
244 .setConnectivityService(new HashMap<>())
248 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name nwTopoServiceName =
249 new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder()
250 .setValue("Network Topo Service")
251 .setValueName("Network Topo Service Name")
254 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1 topologyContext
255 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.Context1Builder()
256 .setTopologyContext(new TopologyContextBuilder()
257 .setNwTopologyService(new NwTopologyServiceBuilder()
258 .setTopology(new HashMap<>())
261 UUID.nameUUIDFromBytes("Network Topo Service".getBytes(Charset.forName("UTF-8")))
263 .setName(Map.of(nwTopoServiceName.key(), nwTopoServiceName))
265 .setTopology(new HashMap<>())
269 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.Context1 notificationContext
270 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.notification.rev221121.Context1Builder()
271 .setNotificationContext(new NotificationContextBuilder()
272 .setNotification(new HashMap<>())
273 .setNotifSubscription(new HashMap<>())
277 ContextBuilder contextBuilder = new ContextBuilder()
278 .setName(Map.of(contextName.key(), contextName))
280 new Uuid(UUID.nameUUIDFromBytes(TAPI_CONTEXT.getBytes(Charset.forName("UTF-8"))).toString()))
281 .setServiceInterfacePoint(new HashMap<>())
282 .addAugmentation(connectivityContext)
283 .addAugmentation(topologyContext)
284 .addAugmentation(notificationContext);
286 // todo: add notification context
287 InstanceIdentifier<Context> contextIID = InstanceIdentifier.builder(Context.class).build();
289 networkTransactionService.put(LogicalDatastoreType.OPERATIONAL, contextIID, contextBuilder.build());
290 networkTransactionService.commit().get();
293 public static GetNotificationListInputBuilder buildGetNotificationListInputBuilder(String subscriptionUuid) {
294 return new GetNotificationListInputBuilder()
295 .setSubscriptionId(new Uuid(UUID.fromString(subscriptionUuid).toString()))