blob: 4b727725a2f9d558f54cda83a71c65be99293dbb [file] [log] [blame]
Brian Stanke0e5c94e2016-03-08 11:20:04 -05001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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
19import org.onosproject.net.DefaultAnnotations;
20import org.onosproject.net.DefaultPort;
21import org.onosproject.net.Device;
22import org.onosproject.net.Element;
23import org.onosproject.net.Port;
24import 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
35
36 private final NetworkId networkId;
37 private final Port realizedBy;
38
39 public DefaultVirtualPort(NetworkId networkId, Device device, PortNumber portNumber, Port realizedBy) {
40 super((Element) device, portNumber, false, DefaultAnnotations.builder().build());
41 this.networkId = networkId;
42 this.realizedBy = realizedBy;
43 }
44
45 public NetworkId networkId() {
46 return networkId;
47 }
48
49 @Override
50 public Port realizedBy() {
51 return realizedBy;
52 }
53
54 @Override
55 public int hashCode() {
56 return Objects.hash(networkId, realizedBy);
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (obj instanceof DefaultVirtualPort) {
65 DefaultVirtualPort that = (DefaultVirtualPort) obj;
66 return super.equals(that) &&
67 Objects.equals(this.networkId, that.networkId) &&
68 Objects.equals(this.realizedBy, that.realizedBy);
69 }
70 return false;
71 }
72
73 @Override
74 public String toString() {
75 return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString();
76 }
77
78}