blob: 2c2012a3d1386260c9a0d2397dda02ebe5ac3dae [file] [log] [blame]
Jian Lib9642832021-01-08 03:18:35 +09001/*
2 * Copyright 2021-present Open Networking Foundation
3 *
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 */
16package org.onosproject.kubevirtnetworking.api;
17
Jian Li8f944d42021-03-23 00:43:29 +090018import org.onlab.util.Tools;
Jian Lib9642832021-01-08 03:18:35 +090019import org.onosproject.event.AbstractEvent;
Jian Li8f944d42021-03-23 00:43:29 +090020import org.onosproject.net.DeviceId;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
Jian Lib9642832021-01-08 03:18:35 +090023
24/**
25 * Kubevirt port event class.
26 */
27public class KubevirtPortEvent extends AbstractEvent<KubevirtPortEvent.Type, KubevirtPort> {
28
Jian Li8f944d42021-03-23 00:43:29 +090029 private final String securityGroupId;
30 private final DeviceId deviceId;
31
Jian Lib9642832021-01-08 03:18:35 +090032 /**
33 * Creates an event of a given type for the specified port.
34 *
35 * @param type kubevirt port event type
36 * @param subject kubevirt port subject
37 */
38 public KubevirtPortEvent(Type type, KubevirtPort subject) {
39 super(type, subject);
Jian Li8f944d42021-03-23 00:43:29 +090040 securityGroupId = null;
41 deviceId = null;
42 }
43
44 /**
45 * Creates an event of a given type for the specified port.
46 *
47 * @param type kubevirt port event type
48 * @param subject kubevirt port subject
49 * @param securityGroupId kubevirt security group ID
50 */
51 public KubevirtPortEvent(Type type, KubevirtPort subject, String securityGroupId) {
52 super(type, subject);
53 this.securityGroupId = securityGroupId;
54 this.deviceId = null;
55 }
56
57 /**
58 * Creates an event of a given type for the specified port.
59 *
60 * @param type kubevirt port event type
61 * @param subject kubevirt port subject
62 * @param deviceId kubevirt device ID
63 */
64 public KubevirtPortEvent(Type type, KubevirtPort subject, DeviceId deviceId) {
65 super(type, subject);
66 this.deviceId = deviceId;
67 this.securityGroupId = null;
Jian Lib9642832021-01-08 03:18:35 +090068 }
69
70 /**
71 * Kubevirt port events.
72 */
73 public enum Type {
74
75 /**
76 * Signifies that a new kubevirt port is created.
77 */
78 KUBEVIRT_PORT_CREATED,
79
80 /**
81 * Signifies that the kubevirt port is updated.
82 */
83 KUBEVIRT_PORT_UPDATED,
84
85 /**
86 * Signifies that the kubevirt port is removed.
87 */
88 KUBEVIRT_PORT_REMOVED,
Jian Li8f944d42021-03-23 00:43:29 +090089
90 /**
91 * Signifies that the kubevirt device is added.
92 */
93 KUBEVIRT_PORT_DEVICE_ADDED,
94
95 /**
96 * Signifies that the kubevirt security group rule is added to a specific port.
97 */
98 KUBEVIRT_PORT_SECURITY_GROUP_ADDED,
99
100 /**
101 * Signifies that the kubevirt security group rule is removed from a specific port.
102 */
103 KUBEVIRT_PORT_SECURITY_GROUP_REMOVED,
104 }
105
106 /**
107 * Returns the security group rule IDs updated.
108 *
109 * @return edgestack security group
110 */
111 public String securityGroupId() {
112 return securityGroupId;
113 }
114
115 @Override
116 public String toString() {
117 return toStringHelper(this)
118 .add("time", Tools.defaultOffsetDataTime(time()))
119 .add("type", type())
120 .add("port", subject())
121 .add("security group", securityGroupId())
122 .toString();
Jian Lib9642832021-01-08 03:18:35 +0900123 }
124}