blob: d5f3efbf6f634d51f992b2c0d4ea577f41939f24 [file] [log] [blame]
Brian Stanke0e5c94e2016-03-08 11:20:04 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Brian Stanke0e5c94e2016-03-08 11:20:04 -05003 *
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.incubator.net.virtual;
18
Yoonseon Han6c603892016-09-01 11:52:21 -070019import org.onosproject.net.ConnectPoint;
Brian Stanke0e5c94e2016-03-08 11:20:04 -050020import org.onosproject.net.DefaultAnnotations;
21import org.onosproject.net.DefaultPort;
22import org.onosproject.net.Device;
23import org.onosproject.net.Element;
Brian Stanke0e5c94e2016-03-08 11:20:04 -050024import org.onosproject.net.PortNumber;
25
26import java.util.Objects;
27
28import static com.google.common.base.MoreObjects.toStringHelper;
29
30/**
31 * Default representation of a virtual port.
32 */
33public final class DefaultVirtualPort extends DefaultPort implements VirtualPort {
34
Brian Stanke0e5c94e2016-03-08 11:20:04 -050035 private final NetworkId networkId;
Yoonseon Han6c603892016-09-01 11:52:21 -070036 private final ConnectPoint realizedBy;
Brian Stanke0e5c94e2016-03-08 11:20:04 -050037
Claudine Chiu579969d2017-10-06 14:32:18 -040038 /**
39 * Creates a virtual port.
40 *
41 * @param networkId network identifier
42 * @param device parent network element
43 * @param portNumber port number
44 * @param realizedBy underling port which realizes this virtual port
45 */
46 public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber,
47 ConnectPoint realizedBy) {
48 this(networkId, device, portNumber, false, realizedBy);
49 }
50
51 /**
52 * Creates a virtual port.
53 *
54 * @param networkId network identifier
55 * @param device parent network element
56 * @param portNumber port number
57 * @param isEnabled indicator whether the port is up and active
58 * @param realizedBy underling port which realizes this virtual port
59 */
60 public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber,
61 boolean isEnabled, ConnectPoint realizedBy) {
62 super((Element) device, portNumber, isEnabled, DefaultAnnotations.builder().build());
Brian Stanke0e5c94e2016-03-08 11:20:04 -050063 this.networkId = networkId;
64 this.realizedBy = realizedBy;
65 }
66
Claudine Chiu579969d2017-10-06 14:32:18 -040067 /**
68 * Returns network identifier.
69 *
70 * @return network identifier
71 */
Brian Stanke0e5c94e2016-03-08 11:20:04 -050072 public NetworkId networkId() {
73 return networkId;
74 }
75
76 @Override
Yoonseon Han6c603892016-09-01 11:52:21 -070077 public ConnectPoint realizedBy() {
Brian Stanke0e5c94e2016-03-08 11:20:04 -050078 return realizedBy;
79 }
80
81 @Override
82 public int hashCode() {
83 return Objects.hash(networkId, realizedBy);
84 }
85
86 @Override
87 public boolean equals(Object obj) {
88 if (this == obj) {
89 return true;
90 }
91 if (obj instanceof DefaultVirtualPort) {
92 DefaultVirtualPort that = (DefaultVirtualPort) obj;
93 return super.equals(that) &&
94 Objects.equals(this.networkId, that.networkId) &&
Yoonseon Han6c603892016-09-01 11:52:21 -070095 Objects.equals(this.number(), that.number()) &&
Brian Stanke0e5c94e2016-03-08 11:20:04 -050096 Objects.equals(this.realizedBy, that.realizedBy);
97 }
98 return false;
99 }
100
101 @Override
102 public String toString() {
103 return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString();
104 }
105
106}