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.DeOperationsListener;
19 import org.opendaylight.transportpce.networkmodel.listeners.DeOperationsListener221;
20 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener121;
21 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener221;
22 import org.opendaylight.transportpce.networkmodel.listeners.DeviceListener710;
23 import org.opendaylight.transportpce.networkmodel.listeners.TcaListener;
24 import org.opendaylight.transportpce.networkmodel.listeners.TcaListener221;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.alarm.rev161014.OrgOpenroadmAlarmListener;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.de.operations.rev161014.OrgOpenroadmDeOperationsListener;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class NodeRegistration {
33 private static final Logger LOG = LoggerFactory.getLogger(NodeRegistration.class);
34 private final String nodeId;
35 private final String nodeVersion;
36 private final NotificationService notificationService;
37 private final DataBroker dataBroker;
38 private final PortMapping portMapping;
39 private final List<ListenerRegistration<?>> listeners;
41 public NodeRegistration(String nodeId, String nodeVersion, NotificationService notificationService,
42 DataBroker dataBroker, PortMapping portMapping) {
44 this.nodeVersion = nodeVersion;
45 this.notificationService = notificationService;
46 this.dataBroker = dataBroker;
47 this.portMapping = portMapping;
48 listeners = new ArrayList<ListenerRegistration<?>>();
51 public void registerListeners() {
52 switch (this.nodeVersion) {
53 case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
54 registerListeners121();
56 case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
57 registerListeners221();
59 case StringConstants.OPENROADM_DEVICE_VERSION_7_1_0:
60 registerListeners710();
63 LOG.debug("Unable to register listeners - unknown device version for {}", this.nodeId);
68 public void unregisterListeners() {
69 LOG.info("Unregistering notification listeners for node: {}", this.nodeId);
70 for (ListenerRegistration<?> listenerRegistration : listeners) {
71 listenerRegistration.close();
75 private void registerListeners121() {
76 OrgOpenroadmAlarmListener alarmListener = new AlarmNotificationListener(this.dataBroker);
77 LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
78 listeners.add(notificationService.registerNotificationListener(alarmListener));
80 OrgOpenroadmDeOperationsListener deOperationsListener = new DeOperationsListener();
81 LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
82 listeners.add(notificationService.registerNotificationListener(deOperationsListener));
84 OrgOpenroadmDeviceListener deviceListener = new DeviceListener121(nodeId, this.portMapping);
85 LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
86 listeners.add(notificationService.registerNotificationListener(deviceListener));
88 TcaListener tcaListener = new TcaListener();
89 LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
90 listeners.add(notificationService.registerNotificationListener(tcaListener));
93 private void registerListeners221() {
94 AlarmNotificationListener221 alarmListener = new AlarmNotificationListener221(dataBroker);
95 LOG.info("Registering notification listener on OrgOpenroadmAlarmListener for node: {}", nodeId);
96 listeners.add(notificationService.registerNotificationListener(alarmListener));
98 DeOperationsListener221 deOperationsListener = new DeOperationsListener221();
99 LOG.info("Registering notification listener on OrgOpenroadmDeOperationsListener for node: {}", nodeId);
100 listeners.add(notificationService.registerNotificationListener(deOperationsListener));
102 DeviceListener221 deviceListener = new DeviceListener221(nodeId, this.portMapping);
103 LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
104 listeners.add(notificationService.registerNotificationListener(deviceListener));
106 TcaListener221 tcaListener = new TcaListener221();
107 LOG.info("Registering notification listener on OrgOpenroadmTcaListener for node: {}", nodeId);
108 listeners.add(notificationService.registerNotificationListener(tcaListener));
111 private void registerListeners710() {
112 DeviceListener710 deviceListener = new DeviceListener710(nodeId, this.portMapping);
113 LOG.info("Registering notification listener on OrgOpenroadmDeviceListener for node: {}", nodeId);
114 listeners.add(notificationService.registerNotificationListener(deviceListener));