blob: e3339a9adf888ea3162ae41ee2ab5bde8d6e704f [file] [log] [blame]
Thomas Vachuska33979fd2015-07-31 11:41:14 -07001/*
2 * Copyright 2015 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.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 */
30public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice {
31
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() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070056 return 31 * super.hashCode() + networkId.hashCode();
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}