2 * Copyright © 2016 AT&T 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.networkmodel.dto;
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.NotificationService;
14 import org.opendaylight.transportpce.common.StringConstants;
15 import org.opendaylight.transportpce.common.mapping.PortMapping;
16 import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener;
17 import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener221;
18 import org.opendaylight.transportpce.networkmodel.listeners.AlarmNotificationListener710;
19 import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener;
20 import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221;
21 import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener710;
22 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121;
23 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221;
24 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener710;
25 import org.opendaylight.transportpce.networkmodel.listeners.TcaListener;
26 import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221;
27 import org.opendaylight.transportpce.networkmodel.listeners.TcaListener710;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class NodeRegistration {
36 private static final Logger LOG = LoggerFactory.getLogger(NodeRegistration.class);
37 private final String nodeId;
38 private final String nodeVersion;
39 private final NotificationService notificationService;
40 private final DataBroker dataBroker;
41 private final PortMapping portMapping;
42 private final List<ListenerRegistration<?>> listeners;
44 public NodeRegistration(String nodeId, String nodeVersion, NotificationService notificationService,
45 DataBroker dataBroker, PortMapping portMapping) {
47 this.nodeVersion = nodeVersion;
48 this.notificationService = notificationService;
49 this.dataBroker = dataBroker;
50 this.portMapping = portMapping;
51 listeners = new ArrayList<ListenerRegistration<?>>();
54 public void registerListeners() {
55 switch (this.nodeVersion) {
56 case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
57 registerListeners121();
59 case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
60 registerListeners221();
62 case StringConstants.OPENROADM_DEVICE_VERSION_7_1:
63 registerListeners710();
66 LOG.debug("Unable to register listeners - unknown device version for {}", this.nodeId);
71 public void unregisterListeners() {
72 LOG.info("Unregistering notification listeners for node: {}", this.nodeId);
73 for (ListenerRegistration<?> listenerRegistration : listeners) {
74 listenerRegistration.close();
78 private void registerListeners121() {
79 OrgOpenroadmAlarmListener alarmListener = new AlarmNotificationListener(this.dataBroker);
80 LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
81 listeners.add(notificationService.registerNotificationListener(alarmListener));
83 OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener();
84 LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
85 listeners.add(notificationService.registerNotificationListener(deOperationsListener));
87 OrgOpenroadmDeviceListener deviceListener = new DeviceListener121(nodeId, this.portMapping);
88 LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
89 listeners.add(notificationService.registerNotificationListener(deviceListener));
91 TcaListener tcaListener = new TcaListener();
92 LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
93 listeners.add(notificationService.registerNotificationListener(tcaListener));
96 private void registerListeners221() {
97 AlarmNotificationListener221 alarmListener = new AlarmNotificationListener221(dataBroker);
98 LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
99 listeners.add(notificationService.registerNotificationListener(alarmListener));
101 DeOperationsListener221 deOperationsListener = new DeOperationsListener221();
102 LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
103 listeners.add(notificationService.registerNotificationListener(deOperationsListener));
105 DeviceListener221 deviceListener = new DeviceListener221(nodeId, this.portMapping);
106 LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
107 listeners.add(notificationService.registerNotificationListener(deviceListener));
109 TcaListener221 tcaListener = new TcaListener221();
110 LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
111 listeners.add(notificationService.registerNotificationListener(tcaListener));
114 private void registerListeners710() {
115 AlarmNotificationListener710 alarmListener = new AlarmNotificationListener710(dataBroker);
116 LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
117 listeners.add(notificationService.registerNotificationListener(alarmListener));
119 DeOperationsListener710 deOperationsListener = new DeOperationsListener710();
120 LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
121 listeners.add(notificationService.registerNotificationListener(deOperationsListener));
123 DeviceListener710 deviceListener = new DeviceListener710(nodeId, this.portMapping);
124 LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
125 listeners.add(notificationService.registerNotificationListener(deviceListener));
127 TcaListener710 tcaListener = new TcaListener710();
128 LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
129 listeners.add(notificationService.registerNotificationListener(tcaListener));