blob: 8c4488ef351a34c6dc8043ee78c0f33ee665a6b5 [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
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
Yoonseon Han6c603892016-09-01 11:52:21 -070038 public DefaultVirtualPort(NetworkId networkId, Device device,
39 PortNumber portNumber, ConnectPoint realizedBy) {
Brian Stanke0e5c94e2016-03-08 11:20:04 -050040 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
Yoonseon Han6c603892016-09-01 11:52:21 -070050 public ConnectPoint realizedBy() {
Brian Stanke0e5c94e2016-03-08 11:20:04 -050051 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) &&
Yoonseon Han6c603892016-09-01 11:52:21 -070068 Objects.equals(this.number(), that.number()) &&
Brian Stanke0e5c94e2016-03-08 11:20:04 -050069 Objects.equals(this.realizedBy, that.realizedBy);
70 }
71 return false;
72 }
73
74 @Override
75 public String toString() {
76 return toStringHelper(this).add("networkId", networkId).add("realizedBy", realizedBy).toString();
77 }
78
79}