blob: 5233f08f52d333bd68aa111dd716078ce07c69dd [file] [log] [blame]
Andrea Campanella101417d2015-12-11 17:58:07 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Andrea Campanella101417d2015-12-11 17:58:07 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.netconf;
18
19import org.onosproject.event.AbstractEvent;
20
Yuta HIGUCHI0454d702017-03-17 10:08:38 -070021import com.google.common.base.MoreObjects;
22
Andreas Papazoisd4712e22016-02-10 15:59:55 +020023import java.util.Optional;
24
Andrea Campanella101417d2015-12-11 17:58:07 -080025/**
Andrea Campanellac3627842017-04-04 18:06:54 +020026 * Describes a NETCONF device related event.
Andrea Campanella101417d2015-12-11 17:58:07 -080027 */
28public final class NetconfDeviceOutputEvent extends
29 AbstractEvent<NetconfDeviceOutputEvent.Type, Object> {
30
31 private final String messagePayload;
Andreas Papazoisd4712e22016-02-10 15:59:55 +020032 private final Optional<Integer> messageID;
Andrea Campanella101417d2015-12-11 17:58:07 -080033 private final NetconfDeviceInfo deviceInfo;
34
35 /**
Andrea Campanellac3627842017-04-04 18:06:54 +020036 * Type of device related events.
Andrea Campanella101417d2015-12-11 17:58:07 -080037 */
38 public enum Type {
39 /**
40 * Signifies that sent a reply to a request.
41 */
42 DEVICE_REPLY,
43
44 /**
45 * Signifies that the device sent a notification.
46 */
47 DEVICE_NOTIFICATION,
48
49 /**
50 * Signifies that the device is not reachable.
51 */
52 DEVICE_UNREGISTERED,
53
54 /**
55 * Signifies that the device has encountered an error.
56 */
57 DEVICE_ERROR,
58
Andrea Campanellac3627842017-04-04 18:06:54 +020059 /**
60 * Signifies that the device has closed the session.
61 * ONOS will try to reopen it, if it fails again
62 * it will mark the device as unreachable.
63 */
64 SESSION_CLOSED,
65
Andrea Campanella101417d2015-12-11 17:58:07 -080066 }
67
68 /**
69 * Creates an event of a given type and for the specified subject and the
70 * current time.
71 *
72 * @param type event type
73 * @param subject event subject
74 * @param payload message from the device
75 * @param msgID id of the message related to the event
76 * @param netconfDeviceInfo device of event
77 */
Andreas Papazoisd4712e22016-02-10 15:59:55 +020078 public NetconfDeviceOutputEvent(Type type, Object subject, String payload,
79 Optional<Integer> msgID,
Andrea Campanella101417d2015-12-11 17:58:07 -080080 NetconfDeviceInfo netconfDeviceInfo) {
81 super(type, subject);
82 messagePayload = payload;
83 this.messageID = msgID;
84 deviceInfo = netconfDeviceInfo;
85 }
86
87 /**
88 * Creates an event of a given type and for the specified subject and time.
89 *
90 * @param type event type
91 * @param subject event subject
92 * @param payload message from the device
93 * @param msgID id of the message related to the event
94 * @param netconfDeviceInfo device of event
Andrea Campanella101417d2015-12-11 17:58:07 -080095 * @param time occurrence time
96 */
Andreas Papazoisd4712e22016-02-10 15:59:55 +020097 public NetconfDeviceOutputEvent(Type type, Object subject, String payload,
98 Optional<Integer> msgID,
99 NetconfDeviceInfo netconfDeviceInfo,
100 long time) {
Andrea Campanella101417d2015-12-11 17:58:07 -0800101 super(type, subject, time);
102 messagePayload = payload;
103 deviceInfo = netconfDeviceInfo;
104 this.messageID = msgID;
105 }
106
Andrea Campanellab029b9e2016-01-29 11:05:36 -0800107 /**
108 * return the message payload of the reply form the device.
109 * @return reply
110 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800111 public String getMessagePayload() {
112 return messagePayload;
113 }
114
Andrea Campanellab029b9e2016-01-29 11:05:36 -0800115 /**
116 * Event-related device information.
117 * @return information about the device
118 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800119 public NetconfDeviceInfo getDeviceInfo() {
120 return deviceInfo;
121 }
122
Andrea Campanellab029b9e2016-01-29 11:05:36 -0800123 /**
124 * Reply messageId.
125 * @return messageId
126 */
Andreas Papazoisd4712e22016-02-10 15:59:55 +0200127 public Optional<Integer> getMessageID() {
Andrea Campanella101417d2015-12-11 17:58:07 -0800128 return messageID;
129 }
Yuta HIGUCHI0454d702017-03-17 10:08:38 -0700130
131 @Override
132 public String toString() {
133 return MoreObjects.toStringHelper(this)
134 .add("messageID", messageID)
135 .add("deviceInfo", deviceInfo)
136 .add("messagePayload", messagePayload)
137 .toString();
138 }
Andrea Campanella101417d2015-12-11 17:58:07 -0800139}