Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 18 | import java.util.Collections; |
| 19 | import java.util.Set; |
| 20 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.AbstractDescription; |
| 22 | import org.onosproject.net.HostLocation; |
| 23 | import org.onosproject.net.SparseAnnotations; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 27 | |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 28 | import com.google.common.collect.ImmutableSet; |
| 29 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 30 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 31 | |
| 32 | /** |
| 33 | * Default implementation of an immutable host description. |
| 34 | */ |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 35 | public class DefaultHostDescription extends AbstractDescription |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 36 | implements HostDescription { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 37 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 38 | private final MacAddress mac; |
| 39 | private final VlanId vlan; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 40 | private final HostLocation location; |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 41 | private final Set<IpAddress> ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 42 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 43 | /** |
| 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 Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 51 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 52 | HostLocation location, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 53 | SparseAnnotations... annotations) { |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 54 | this(mac, vlan, location, Collections.<IpAddress>emptySet(), |
| 55 | annotations); |
Ayaka Koshibe | 1a10098 | 2014-09-13 19:32:19 -0700 | [diff] [blame] | 56 | } |
| 57 | |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 58 | /** |
| 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 |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 64 | * @param ip host IP address |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 65 | * @param annotations optional key/value annotations map |
| 66 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 67 | public DefaultHostDescription(MacAddress mac, VlanId vlan, |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 68 | HostLocation location, IpAddress ip, |
tom | f5d85d4 | 2014-10-02 05:27:56 -0700 | [diff] [blame] | 69 | SparseAnnotations... annotations) { |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 70 | 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 Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 83 | HostLocation location, Set<IpAddress> ip, |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 84 | SparseAnnotations... annotations) { |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 85 | super(annotations); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 86 | this.mac = mac; |
| 87 | this.vlan = vlan; |
tom | 27ae0e6 | 2014-10-01 20:35:01 -0700 | [diff] [blame] | 88 | this.location = location; |
Yuta HIGUCHI | 5fa3dc0 | 2014-10-15 17:08:13 -0700 | [diff] [blame] | 89 | this.ip = ImmutableSet.copyOf(ip); |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 93 | public MacAddress hwAddress() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 94 | return mac; |
| 95 | } |
| 96 | |
| 97 | @Override |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 98 | public VlanId vlan() { |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 99 | return vlan; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public HostLocation location() { |
| 104 | return location; |
| 105 | } |
| 106 | |
| 107 | @Override |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 108 | public Set<IpAddress> ipAddress() { |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 109 | return ip; |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public String toString() { |
| 114 | return toStringHelper(this) |
| 115 | .add("mac", mac) |
| 116 | .add("vlan", vlan) |
| 117 | .add("location", location) |
tom | 093340b | 2014-10-10 00:15:36 -0700 | [diff] [blame] | 118 | .add("ipAddress", ip) |
Ayaka Koshibe | 74a2392 | 2014-09-09 16:45:39 -0700 | [diff] [blame] | 119 | .toString(); |
| 120 | } |
| 121 | |
| 122 | } |