blob: 98e3e1e4f3ecb0f528f99190895e634a4260698f [file] [log] [blame]
Thomas Vachuska33979fd2015-07-31 11:41:14 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska33979fd2015-07-31 11:41:14 -07003 *
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.incubator.net.virtual;
17
18import org.onlab.packet.ChassisId;
19import org.onosproject.net.DefaultDevice;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.provider.ProviderId;
22
23import java.util.Objects;
24
25import static com.google.common.base.MoreObjects.*;
26
27/**
28 * Default representation of a virtual device.
29 */
Brian Stanke0e5c94e2016-03-08 11:20:04 -050030public final class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice {
Thomas Vachuska33979fd2015-07-31 11:41:14 -070031
32 private static final String VIRTUAL = "virtual";
33 private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL);
34
35 private final NetworkId networkId;
36
37 /**
38 * Creates a network element attributed to the specified provider.
39 *
40 * @param networkId network identifier
41 * @param id device identifier
42 */
43 public DefaultVirtualDevice(NetworkId networkId, DeviceId id) {
44 super(PID, id, Type.VIRTUAL, VIRTUAL, VIRTUAL, VIRTUAL, VIRTUAL,
45 new ChassisId(0));
46 this.networkId = networkId;
47 }
48
49 @Override
50 public NetworkId networkId() {
51 return networkId;
52 }
53
54 @Override
55 public int hashCode() {
Brian Stanke0e5c94e2016-03-08 11:20:04 -050056 return Objects.hash(networkId);
Thomas Vachuska33979fd2015-07-31 11:41:14 -070057 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (this == obj) {
62 return true;
63 }
64 if (obj instanceof DefaultVirtualDevice) {
65 DefaultVirtualDevice that = (DefaultVirtualDevice) obj;
66 return super.equals(that) && Objects.equals(this.networkId, that.networkId);
67 }
68 return false;
69 }
70
71 @Override
72 public String toString() {
73 return toStringHelper(this).add("networkId", networkId).toString();
74 }
75}