blob: 5d9134b433445635fee5aeac5fe73ded08f3e573 [file] [log] [blame]
YuanyouZhangf26445a2015-07-22 17:13:18 +08001/*
2 * Copyright 2015 Open Networking Laboratory
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.ovsdb.controller;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21import java.util.Set;
22
23import org.onlab.packet.IpAddress;
24import org.onlab.packet.MacAddress;
25
26/**
27 * This class is default event subject that implements OvsdbEventSubject.
28 */
29public class DefaultEventSubject implements OvsdbEventSubject {
30 private final MacAddress mac;
31 private final Set<IpAddress> ips;
32 private final OvsdbPortName portname;
33 private final OvsdbPortNumber portnumber;
34 private final OvsdbDatapathId dpid;
35 private final OvsdbPortType portType;
36 private final OvsdbIfaceId ifaceid;
37
38 /**
39 * Creates an end-station event subject using the supplied information.
40 *
41 * @param mac host MAC address
42 * @param ips host MAC ips
43 * @param portname port name
44 * @param portnumber port number
45 * @param dpid ovs dpid
46 * @param portType port type
47 * @param ifaceid vm ifaceid
48 */
49 public DefaultEventSubject(MacAddress mac, Set<IpAddress> ips,
50 OvsdbPortName portname, OvsdbPortNumber portnumber, OvsdbDatapathId dpid,
51 OvsdbPortType portType, OvsdbIfaceId ifaceid) {
52 super();
53 this.mac = mac;
54 this.ips = ips;
55 this.portname = portname;
56 this.portnumber = portnumber;
57 this.dpid = dpid;
58 this.portType = portType;
59 this.ifaceid = ifaceid;
60 }
61
62 @Override
63 public MacAddress hwAddress() {
64 return mac;
65 }
66
67 @Override
68 public Set<IpAddress> ipAddress() {
69 return ips;
70 }
71
72 @Override
73 public OvsdbPortName portName() {
74 return portname;
75 }
76
77 @Override
78 public OvsdbPortNumber portNumber() {
79 return portnumber;
80 }
81
82 @Override
83 public OvsdbPortType portType() {
84 return portType;
85 }
86
87 @Override
88 public OvsdbDatapathId dpid() {
89 return dpid;
90 }
91
92 @Override
93 public OvsdbIfaceId ifaceid() {
94 return ifaceid;
95 }
96
97 @Override
98 public int hashCode() {
99 return Objects.hash(mac, portname, portnumber, dpid, portType, ifaceid);
100 }
101
102 @Override
103 public boolean equals(Object obj) {
104 if (this == obj) {
105 return true;
106 }
107 if (obj instanceof DefaultEventSubject) {
108 final DefaultEventSubject other = (DefaultEventSubject) obj;
109 return Objects.equals(this.mac, other.mac)
110 && Objects.equals(this.portname, other.portname)
111 && Objects.equals(this.portnumber, other.portnumber)
112 && Objects.equals(this.dpid, other.dpid)
113 && Objects.equals(this.portType, other.portType)
114 && Objects.equals(this.ifaceid, other.ifaceid);
115 }
116 return false;
117 }
118
119 @Override
120 public String toString() {
121 return toStringHelper(this).add("mac", mac).add("portname", portname)
122 .add("portnumber", portnumber).add("portType", portType)
123 .add("ipAddresses", ips).add("dpid", dpid).add("ifaceid", ifaceid)
124 .toString();
125 }
126}