blob: c41a77cfa3cccfe5dddc6471c8e8611623ac9810 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Ayaka Koshibe74a23922014-09-09 16:45:39 -070016package org.onlab.onos.net.host;
17
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070018import java.util.Collections;
19import java.util.Set;
20
tomf5d85d42014-10-02 05:27:56 -070021import org.onlab.onos.net.AbstractDescription;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070022import org.onlab.onos.net.HostLocation;
tomf5d85d42014-10-02 05:27:56 -070023import org.onlab.onos.net.SparseAnnotations;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070024import org.onlab.packet.IpAddress;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070025import org.onlab.packet.MacAddress;
26import org.onlab.packet.VlanId;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070027
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070028import com.google.common.collect.ImmutableSet;
29
tom27ae0e62014-10-01 20:35:01 -070030import static com.google.common.base.MoreObjects.toStringHelper;
31
32/**
33 * Default implementation of an immutable host description.
34 */
tomf5d85d42014-10-02 05:27:56 -070035public class DefaultHostDescription extends AbstractDescription
tom27ae0e62014-10-01 20:35:01 -070036 implements HostDescription {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070037
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070038 private final MacAddress mac;
39 private final VlanId vlan;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070040 private final HostLocation location;
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070041 private final Set<IpAddress> ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -070042
tom27ae0e62014-10-01 20:35:01 -070043 /**
44 * Creates a host description using the supplied information.
45 *
46 * @param mac host MAC address
47 * @param vlan host VLAN identifier
48 * @param location host location
49 * @param annotations optional key/value annotations map
50 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070051 public DefaultHostDescription(MacAddress mac, VlanId vlan,
tom27ae0e62014-10-01 20:35:01 -070052 HostLocation location,
tomf5d85d42014-10-02 05:27:56 -070053 SparseAnnotations... annotations) {
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070054 this(mac, vlan, location, Collections.<IpAddress>emptySet(),
55 annotations);
Ayaka Koshibe1a100982014-09-13 19:32:19 -070056 }
57
tom27ae0e62014-10-01 20:35:01 -070058 /**
59 * Creates a host description using the supplied information.
60 *
61 * @param mac host MAC address
62 * @param vlan host VLAN identifier
63 * @param location host location
tom093340b2014-10-10 00:15:36 -070064 * @param ip host IP address
tom27ae0e62014-10-01 20:35:01 -070065 * @param annotations optional key/value annotations map
66 */
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070067 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070068 HostLocation location, IpAddress ip,
tomf5d85d42014-10-02 05:27:56 -070069 SparseAnnotations... annotations) {
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070070 this(mac, vlan, location, ImmutableSet.of(ip), annotations);
71 }
72
73 /**
74 * Creates a host description using the supplied information.
75 *
76 * @param mac host MAC address
77 * @param vlan host VLAN identifier
78 * @param location host location
79 * @param ip host IP addresses
80 * @param annotations optional key/value annotations map
81 */
82 public DefaultHostDescription(MacAddress mac, VlanId vlan,
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -070083 HostLocation location, Set<IpAddress> ip,
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070084 SparseAnnotations... annotations) {
tom27ae0e62014-10-01 20:35:01 -070085 super(annotations);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070086 this.mac = mac;
87 this.vlan = vlan;
tom27ae0e62014-10-01 20:35:01 -070088 this.location = location;
Yuta HIGUCHI5fa3dc02014-10-15 17:08:13 -070089 this.ip = ImmutableSet.copyOf(ip);
Ayaka Koshibe74a23922014-09-09 16:45:39 -070090 }
91
92 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070093 public MacAddress hwAddress() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070094 return mac;
95 }
96
97 @Override
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070098 public VlanId vlan() {
Ayaka Koshibe74a23922014-09-09 16:45:39 -070099 return vlan;
100 }
101
102 @Override
103 public HostLocation location() {
104 return location;
105 }
106
107 @Override
Pavlin Radoslavov33f228a2014-10-27 19:33:16 -0700108 public Set<IpAddress> ipAddress() {
tom093340b2014-10-10 00:15:36 -0700109 return ip;
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700110 }
111
112 @Override
113 public String toString() {
114 return toStringHelper(this)
115 .add("mac", mac)
116 .add("vlan", vlan)
117 .add("location", location)
tom093340b2014-10-10 00:15:36 -0700118 .add("ipAddress", ip)
Ayaka Koshibe74a23922014-09-09 16:45:39 -0700119 .toString();
120 }
121
122}