blob: 9a22552df040a919cc8422eba6a7cca437818b94 [file] [log] [blame]
Hyunsun Moon4c396632016-05-13 04:17:53 -07001/*
2 * Copyright 2016-present 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.xosclient.api;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21
22import java.util.Map;
23import java.util.Objects;
24
25/**
26 * Representation of port in a CORD VTN controlled network, it can be for VM
27 * or container.
28 */
29public final class VtnPort {
30
31 private final VtnPortId id;
32 private final String name;
33 private final VtnServiceId serviceId;
34 private final MacAddress mac;
35 private final IpAddress ip;
36 // TODO remove this when XOS provides vSG information
37 private final Map<IpAddress, MacAddress> addressPairs;
38
39
40 /**
41 * Creates a new vtn port with the specified entities.
42 *
43 * @param id vtn port id
44 * @param name vtn port name
45 * @param serviceId id of the service this port is in
46 * @param mac mac address
47 * @param ip ip address
48 * @param addressPairs ip and mac pairs of nested container
49 */
50 public VtnPort(VtnPortId id,
51 String name,
52 VtnServiceId serviceId,
53 MacAddress mac,
54 IpAddress ip,
55 Map<IpAddress, MacAddress> addressPairs) {
56 this.id = id;
57 this.name = name;
58 this.serviceId = serviceId;
59 this.mac = mac;
60 this.ip = ip;
61 this.addressPairs = addressPairs;
62 }
63
64 /**
65 * Returns vtn port ID.
66 *
67 * @return vtn port id
68 */
69 public VtnPortId id() {
70 return id;
71 }
72
73 /**
74 * Returns vtn port name.
75 *
76 * @return vtn port name
77 */
78 public String name() {
79 return name;
80 }
81
82 /**
83 * Returns the ID of the service this port is in.
84 *
85 * @return vtn service id
86 */
87 public VtnServiceId serviceId() {
88 return serviceId;
89 }
90
91 /**
92 * Returns MAC address of this port.
93 *
94 * @return mac address
95 */
96 public MacAddress mac() {
97 return mac;
98 }
99
100 /**
101 * Returns IP address of this port.
102 *
103 * @return ip address
104 */
105 public IpAddress ip() {
106 return ip;
107 }
108
109 /**
110 * Returns address pairs of the nested containers inside.
111 *
112 * @return map of ip and address
113 */
114 public Map<IpAddress, MacAddress> addressPairs() {
115 return addressPairs;
116 }
117
118 @Override
119 public int hashCode() {
120 return Objects.hash(id);
121 }
122
123 @Override
124 public boolean equals(Object obj) {
125 if (this == obj) {
126 return true;
127 }
128 if (!(obj instanceof VtnPort)) {
129 return false;
130 }
131 final VtnPort other = (VtnPort) obj;
132 return Objects.equals(this.id, other.id);
133 }
134
135 @Override
136 public String toString() {
137 return MoreObjects.toStringHelper(this)
138 .add("id", id)
139 .add("name", name)
140 .add("serviceId", serviceId)
141 .add("mac", mac)
142 .add("ip", ip)
143 .add("addressPairs", addressPairs)
144 .toString();
145 }
146}