added VLANID construct
Change-Id: Ia58abb268d52639215f289052bbf8802992f98a6
Showing
9 changed files
with
62 additions
and
14 deletions
| ... | @@ -10,6 +10,7 @@ import java.util.Set; | ... | @@ -10,6 +10,7 @@ import java.util.Set; |
| 10 | import org.onlab.onos.net.provider.ProviderId; | 10 | import org.onlab.onos.net.provider.ProviderId; |
| 11 | import org.onlab.packet.IPAddress; | 11 | import org.onlab.packet.IPAddress; |
| 12 | import org.onlab.packet.MACAddress; | 12 | import org.onlab.packet.MACAddress; |
| 13 | +import org.onlab.packet.VLANID; | ||
| 13 | 14 | ||
| 14 | /** | 15 | /** |
| 15 | * A basic implementation of a Host. | 16 | * A basic implementation of a Host. |
| ... | @@ -17,12 +18,12 @@ import org.onlab.packet.MACAddress; | ... | @@ -17,12 +18,12 @@ import org.onlab.packet.MACAddress; |
| 17 | public class DefaultHost extends AbstractElement implements Host { | 18 | public class DefaultHost extends AbstractElement implements Host { |
| 18 | 19 | ||
| 19 | private final MACAddress mac; | 20 | private final MACAddress mac; |
| 20 | - private final short vlan; | 21 | + private final VLANID vlan; |
| 21 | private final HostLocation location; | 22 | private final HostLocation location; |
| 22 | private final Set<IPAddress> ips; | 23 | private final Set<IPAddress> ips; |
| 23 | 24 | ||
| 24 | - public DefaultHost(ProviderId providerId, ElementId id, MACAddress mac, | 25 | + public DefaultHost(ProviderId providerId, HostId id, MACAddress mac, |
| 25 | - short vlan, HostLocation loc, Set<IPAddress> ips) { | 26 | + VLANID vlan, HostLocation loc, Set<IPAddress> ips) { |
| 26 | super(providerId, id); | 27 | super(providerId, id); |
| 27 | this.mac = mac; | 28 | this.mac = mac; |
| 28 | this.vlan = vlan; | 29 | this.vlan = vlan; |
| ... | @@ -51,7 +52,7 @@ public class DefaultHost extends AbstractElement implements Host { | ... | @@ -51,7 +52,7 @@ public class DefaultHost extends AbstractElement implements Host { |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | @Override | 54 | @Override |
| 54 | - public short vlan() { | 55 | + public VLANID vlan() { |
| 55 | return vlan; | 56 | return vlan; |
| 56 | } | 57 | } |
| 57 | 58 | ... | ... |
| ... | @@ -2,6 +2,7 @@ package org.onlab.onos.net; | ... | @@ -2,6 +2,7 @@ package org.onlab.onos.net; |
| 2 | 2 | ||
| 3 | import org.onlab.packet.IPAddress; | 3 | import org.onlab.packet.IPAddress; |
| 4 | import org.onlab.packet.MACAddress; | 4 | import org.onlab.packet.MACAddress; |
| 5 | +import org.onlab.packet.VLANID; | ||
| 5 | 6 | ||
| 6 | import java.util.Set; | 7 | import java.util.Set; |
| 7 | 8 | ||
| ... | @@ -30,7 +31,7 @@ public interface Host extends Element { | ... | @@ -30,7 +31,7 @@ public interface Host extends Element { |
| 30 | * | 31 | * |
| 31 | * @return VLAN ID value | 32 | * @return VLAN ID value |
| 32 | */ | 33 | */ |
| 33 | - short vlan(); | 34 | + VLANID vlan(); |
| 34 | 35 | ||
| 35 | /** | 36 | /** |
| 36 | * Returns set of IP addresses currently bound to the host MAC address. | 37 | * Returns set of IP addresses currently bound to the host MAC address. | ... | ... |
| ... | @@ -8,17 +8,18 @@ import java.util.Set; | ... | @@ -8,17 +8,18 @@ import java.util.Set; |
| 8 | import org.onlab.onos.net.HostLocation; | 8 | import org.onlab.onos.net.HostLocation; |
| 9 | import org.onlab.packet.IPAddress; | 9 | import org.onlab.packet.IPAddress; |
| 10 | import org.onlab.packet.MACAddress; | 10 | import org.onlab.packet.MACAddress; |
| 11 | +import org.onlab.packet.VLANID; | ||
| 11 | 12 | ||
| 12 | import com.google.common.collect.ImmutableSet; | 13 | import com.google.common.collect.ImmutableSet; |
| 13 | 14 | ||
| 14 | public class DefaultHostDescription implements HostDescription { | 15 | public class DefaultHostDescription implements HostDescription { |
| 15 | 16 | ||
| 16 | private final MACAddress mac; | 17 | private final MACAddress mac; |
| 17 | - private final short vlan; | 18 | + private final VLANID vlan; |
| 18 | private final HostLocation location; | 19 | private final HostLocation location; |
| 19 | private final Set<IPAddress> ips; | 20 | private final Set<IPAddress> ips; |
| 20 | 21 | ||
| 21 | - public DefaultHostDescription(MACAddress mac, short vlan, | 22 | + public DefaultHostDescription(MACAddress mac, VLANID vlan, |
| 22 | HostLocation loc, Set<IPAddress> ips) { | 23 | HostLocation loc, Set<IPAddress> ips) { |
| 23 | this.mac = mac; | 24 | this.mac = mac; |
| 24 | this.vlan = vlan; | 25 | this.vlan = vlan; |
| ... | @@ -32,7 +33,7 @@ public class DefaultHostDescription implements HostDescription { | ... | @@ -32,7 +33,7 @@ public class DefaultHostDescription implements HostDescription { |
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | @Override | 35 | @Override |
| 35 | - public short vlan() { | 36 | + public VLANID vlan() { |
| 36 | return vlan; | 37 | return vlan; |
| 37 | } | 38 | } |
| 38 | 39 | ... | ... |
| ... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.Description; | ... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.Description; |
| 6 | import org.onlab.onos.net.HostLocation; | 6 | import org.onlab.onos.net.HostLocation; |
| 7 | import org.onlab.packet.IPAddress; | 7 | import org.onlab.packet.IPAddress; |
| 8 | import org.onlab.packet.MACAddress; | 8 | import org.onlab.packet.MACAddress; |
| 9 | +import org.onlab.packet.VLANID; | ||
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| 11 | * Information describing host and its location. | 12 | * Information describing host and its location. |
| ... | @@ -24,7 +25,7 @@ public interface HostDescription extends Description { | ... | @@ -24,7 +25,7 @@ public interface HostDescription extends Description { |
| 24 | * | 25 | * |
| 25 | * @return the VLAN ID value | 26 | * @return the VLAN ID value |
| 26 | */ | 27 | */ |
| 27 | - short vlan(); | 28 | + VLANID vlan(); |
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | * Returns the location of the host on the network edge. | 31 | * Returns the location of the host on the network edge. | ... | ... |
| ... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.Host; | ... | @@ -6,6 +6,7 @@ import org.onlab.onos.net.Host; |
| 6 | import org.onlab.onos.net.HostId; | 6 | import org.onlab.onos.net.HostId; |
| 7 | import org.onlab.packet.IPAddress; | 7 | import org.onlab.packet.IPAddress; |
| 8 | import org.onlab.packet.MACAddress; | 8 | import org.onlab.packet.MACAddress; |
| 9 | +import org.onlab.packet.VLANID; | ||
| 9 | 10 | ||
| 10 | import java.util.Set; | 11 | import java.util.Set; |
| 11 | 12 | ||
| ... | @@ -43,7 +44,7 @@ public interface HostService { | ... | @@ -43,7 +44,7 @@ public interface HostService { |
| 43 | * @return set of hosts in the given vlan id | 44 | * @return set of hosts in the given vlan id |
| 44 | */ | 45 | */ |
| 45 | // FIXME: change long to VLanId | 46 | // FIXME: change long to VLanId |
| 46 | - Set<Host> getHostsByVlan(long vlanId); | 47 | + Set<Host> getHostsByVlan(VLANID vlanId); |
| 47 | 48 | ||
| 48 | /** | 49 | /** |
| 49 | * Returns the set of hosts that have the specified MAC address. | 50 | * Returns the set of hosts that have the specified MAC address. | ... | ... |
| ... | @@ -23,6 +23,7 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry; | ... | @@ -23,6 +23,7 @@ import org.onlab.onos.net.provider.AbstractProviderRegistry; |
| 23 | import org.onlab.onos.net.provider.AbstractProviderService; | 23 | import org.onlab.onos.net.provider.AbstractProviderService; |
| 24 | import org.onlab.packet.IPAddress; | 24 | import org.onlab.packet.IPAddress; |
| 25 | import org.onlab.packet.MACAddress; | 25 | import org.onlab.packet.MACAddress; |
| 26 | +import org.onlab.packet.VLANID; | ||
| 26 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
| 27 | 28 | ||
| 28 | import java.util.Set; | 29 | import java.util.Set; |
| ... | @@ -85,7 +86,7 @@ public class SimpleHostManager | ... | @@ -85,7 +86,7 @@ public class SimpleHostManager |
| 85 | } | 86 | } |
| 86 | 87 | ||
| 87 | @Override | 88 | @Override |
| 88 | - public Set<Host> getHostsByVlan(long vlanId) { | 89 | + public Set<Host> getHostsByVlan(VLANID vlanId) { |
| 89 | return store.getHosts(vlanId); | 90 | return store.getHosts(vlanId); |
| 90 | } | 91 | } |
| 91 | 92 | ... | ... |
| ... | @@ -21,6 +21,7 @@ import org.onlab.onos.net.host.HostEvent; | ... | @@ -21,6 +21,7 @@ import org.onlab.onos.net.host.HostEvent; |
| 21 | import org.onlab.onos.net.provider.ProviderId; | 21 | import org.onlab.onos.net.provider.ProviderId; |
| 22 | import org.onlab.packet.IPAddress; | 22 | import org.onlab.packet.IPAddress; |
| 23 | import org.onlab.packet.MACAddress; | 23 | import org.onlab.packet.MACAddress; |
| 24 | +import org.onlab.packet.VLANID; | ||
| 24 | 25 | ||
| 25 | import com.google.common.collect.HashMultimap; | 26 | import com.google.common.collect.HashMultimap; |
| 26 | import com.google.common.collect.ImmutableSet; | 27 | import com.google.common.collect.ImmutableSet; |
| ... | @@ -149,10 +150,10 @@ public class SimpleHostStore { | ... | @@ -149,10 +150,10 @@ public class SimpleHostStore { |
| 149 | * @param vlanId vlan id | 150 | * @param vlanId vlan id |
| 150 | * @return set of hosts in the vlan | 151 | * @return set of hosts in the vlan |
| 151 | */ | 152 | */ |
| 152 | - Set<Host> getHosts(long vlanId) { | 153 | + Set<Host> getHosts(VLANID vlanId) { |
| 153 | Set<Host> vlanset = new HashSet<Host>(); | 154 | Set<Host> vlanset = new HashSet<Host>(); |
| 154 | for (Host h : hosts.values()) { | 155 | for (Host h : hosts.values()) { |
| 155 | - if (h.vlan() == vlanId) { | 156 | + if (h.vlan().equals(vlanId)) { |
| 156 | vlanset.add(h); | 157 | vlanset.add(h); |
| 157 | } | 158 | } |
| 158 | } | 159 | } | ... | ... |
| ... | @@ -10,7 +10,7 @@ public class IPAddress { | ... | @@ -10,7 +10,7 @@ public class IPAddress { |
| 10 | //IP Versions | 10 | //IP Versions |
| 11 | public enum Version { INET, INET6 }; | 11 | public enum Version { INET, INET6 }; |
| 12 | 12 | ||
| 13 | - //lengths of addresses, in bytes | 13 | + //lengths of address, in bytes |
| 14 | public static final int INET_LEN = 4; | 14 | public static final int INET_LEN = 4; |
| 15 | public static final int INET6_LEN = 6; | 15 | public static final int INET6_LEN = 6; |
| 16 | 16 | ... | ... |
| 1 | +package org.onlab.packet; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Representation of a VLAN ID. | ||
| 5 | + */ | ||
| 6 | +public class VLANID { | ||
| 7 | + // A VLAN ID is 12 bits, short is close | ||
| 8 | + private final short value; | ||
| 9 | + | ||
| 10 | + public VLANID(short value) { | ||
| 11 | + this.value = value; | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public short toShort() { | ||
| 15 | + return this.value; | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + @Override | ||
| 19 | + public boolean equals(Object obj) { | ||
| 20 | + if (this == obj) { | ||
| 21 | + return true; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + if (obj instanceof VLANID) { | ||
| 25 | + return true; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + VLANID other = (VLANID) obj; | ||
| 29 | + if (this.value == other.value) { | ||
| 30 | + return true; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + return false; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public int hashCode() { | ||
| 38 | + return this.value; | ||
| 39 | + } | ||
| 40 | +} | ||
| 41 | + |
-
Please register or login to post a comment