54a22a46964806af7085d73ccec90347208a8935
[onosfw.git] /
1 /*
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  */
16 package org.onosproject.incubator.net.virtual;
17
18 import org.onlab.packet.ChassisId;
19 import org.onosproject.net.DefaultDevice;
20 import org.onosproject.net.DeviceId;
21 import org.onosproject.net.provider.ProviderId;
22
23 import java.util.Objects;
24
25 import static com.google.common.base.MoreObjects.*;
26
27 /**
28  * Default representation of a virtual device.
29  */
30 public 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() {
56         return 31 * super.hashCode() + Objects.hash(networkId);
57     }
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 }