Added isLinkLocal predicate to MacAddress and used it in ReactiveForwarding.
Showing
3 changed files
with
37 additions
and
23 deletions
... | @@ -137,6 +137,11 @@ public class ReactiveForwarding { | ... | @@ -137,6 +137,11 @@ public class ReactiveForwarding { |
137 | 137 | ||
138 | HostId id = HostId.hostId(ethPkt.getDestinationMAC()); | 138 | HostId id = HostId.hostId(ethPkt.getDestinationMAC()); |
139 | 139 | ||
140 | + // Do not process link-local addresses in any way. | ||
141 | + if (id.mac().isLinkLocal()) { | ||
142 | + return; | ||
143 | + } | ||
144 | + | ||
140 | // Do we know who this is for? If not, flood and bail. | 145 | // Do we know who this is for? If not, flood and bail. |
141 | Host dst = hostService.getHost(id); | 146 | Host dst = hostService.getHost(id); |
142 | if (dst == null) { | 147 | if (dst == null) { | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -22,7 +22,6 @@ import java.util.Arrays; | ... | @@ -22,7 +22,6 @@ import java.util.Arrays; |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * The class representing MAC address. | 24 | * The class representing MAC address. |
25 | - * | ||
26 | */ | 25 | */ |
27 | public class MacAddress { | 26 | public class MacAddress { |
28 | 27 | ||
... | @@ -32,6 +31,11 @@ public class MacAddress { | ... | @@ -32,6 +31,11 @@ public class MacAddress { |
32 | public static final byte[] ZERO_MAC_ADDRESS = ZERO.getAddress(); | 31 | public static final byte[] ZERO_MAC_ADDRESS = ZERO.getAddress(); |
33 | public static final byte[] BROADCAST_MAC = BROADCAST.getAddress(); | 32 | public static final byte[] BROADCAST_MAC = BROADCAST.getAddress(); |
34 | 33 | ||
34 | + private static final byte[] LL = new byte[]{ | ||
35 | + 0x01, (byte) 0x80, (byte) 0xc2, 0x00, 0x00, | ||
36 | + 0x00, 0x0e, 0x03 | ||
37 | + }; | ||
38 | + | ||
35 | public static final int MAC_ADDRESS_LENGTH = 6; | 39 | public static final int MAC_ADDRESS_LENGTH = 6; |
36 | private byte[] address = new byte[MacAddress.MAC_ADDRESS_LENGTH]; | 40 | private byte[] address = new byte[MacAddress.MAC_ADDRESS_LENGTH]; |
37 | 41 | ||
... | @@ -43,12 +47,10 @@ public class MacAddress { | ... | @@ -43,12 +47,10 @@ public class MacAddress { |
43 | * Returns a MAC address instance representing the value of the specified | 47 | * Returns a MAC address instance representing the value of the specified |
44 | * {@code String}. | 48 | * {@code String}. |
45 | * | 49 | * |
46 | - * @param address | 50 | + * @param address the String representation of the MAC Address to be parsed. |
47 | - * the String representation of the MAC Address to be parsed. | ||
48 | * @return a MAC Address instance representing the value of the specified | 51 | * @return a MAC Address instance representing the value of the specified |
49 | - * {@code String}. | 52 | + * {@code String}. |
50 | - * @throws IllegalArgumentException | 53 | + * @throws IllegalArgumentException if the string cannot be parsed as a MAC address. |
51 | - * if the string cannot be parsed as a MAC address. | ||
52 | */ | 54 | */ |
53 | public static MacAddress valueOf(final String address) { | 55 | public static MacAddress valueOf(final String address) { |
54 | final String[] elements = address.split(":"); | 56 | final String[] elements = address.split(":"); |
... | @@ -71,17 +73,15 @@ public class MacAddress { | ... | @@ -71,17 +73,15 @@ public class MacAddress { |
71 | * Returns a MAC address instance representing the specified {@code byte} | 73 | * Returns a MAC address instance representing the specified {@code byte} |
72 | * array. | 74 | * array. |
73 | * | 75 | * |
74 | - * @param address | 76 | + * @param address the byte array to be parsed. |
75 | - * the byte array to be parsed. | ||
76 | * @return a MAC address instance representing the specified {@code byte} | 77 | * @return a MAC address instance representing the specified {@code byte} |
77 | - * array. | 78 | + * array. |
78 | - * @throws IllegalArgumentException | 79 | + * @throws IllegalArgumentException if the byte array cannot be parsed as a MAC address. |
79 | - * if the byte array cannot be parsed as a MAC address. | ||
80 | */ | 80 | */ |
81 | public static MacAddress valueOf(final byte[] address) { | 81 | public static MacAddress valueOf(final byte[] address) { |
82 | if (address.length != MacAddress.MAC_ADDRESS_LENGTH) { | 82 | if (address.length != MacAddress.MAC_ADDRESS_LENGTH) { |
83 | throw new IllegalArgumentException("the length is not " | 83 | throw new IllegalArgumentException("the length is not " |
84 | - + MacAddress.MAC_ADDRESS_LENGTH); | 84 | + + MacAddress.MAC_ADDRESS_LENGTH); |
85 | } | 85 | } |
86 | 86 | ||
87 | return new MacAddress(address); | 87 | return new MacAddress(address); |
... | @@ -92,19 +92,17 @@ public class MacAddress { | ... | @@ -92,19 +92,17 @@ public class MacAddress { |
92 | * value. The lower 48 bits of the long value are used to parse as a MAC | 92 | * value. The lower 48 bits of the long value are used to parse as a MAC |
93 | * address. | 93 | * address. |
94 | * | 94 | * |
95 | - * @param address | 95 | + * @param address the long value to be parsed. The lower 48 bits are used for a |
96 | - * the long value to be parsed. The lower 48 bits are used for a | 96 | + * MAC address. |
97 | - * MAC address. | ||
98 | * @return a MAC address instance representing the specified {@code long} | 97 | * @return a MAC address instance representing the specified {@code long} |
99 | - * value. | 98 | + * value. |
100 | - * @throws IllegalArgumentException | 99 | + * @throws IllegalArgumentException if the long value cannot be parsed as a MAC address. |
101 | - * if the long value cannot be parsed as a MAC address. | ||
102 | */ | 100 | */ |
103 | public static MacAddress valueOf(final long address) { | 101 | public static MacAddress valueOf(final long address) { |
104 | - final byte[] addressInBytes = new byte[] { | 102 | + final byte[] addressInBytes = new byte[]{ |
105 | (byte) (address >> 40 & 0xff), (byte) (address >> 32 & 0xff), | 103 | (byte) (address >> 40 & 0xff), (byte) (address >> 32 & 0xff), |
106 | (byte) (address >> 24 & 0xff), (byte) (address >> 16 & 0xff), | 104 | (byte) (address >> 24 & 0xff), (byte) (address >> 16 & 0xff), |
107 | - (byte) (address >> 8 & 0xff), (byte) (address >> 0 & 0xff) }; | 105 | + (byte) (address >> 8 & 0xff), (byte) (address >> 0 & 0xff)}; |
108 | 106 | ||
109 | return new MacAddress(addressInBytes); | 107 | return new MacAddress(addressInBytes); |
110 | } | 108 | } |
... | @@ -122,7 +120,7 @@ public class MacAddress { | ... | @@ -122,7 +120,7 @@ public class MacAddress { |
122 | * Returns the value of the {@code MACAddress} as a {@code byte} array. | 120 | * Returns the value of the {@code MACAddress} as a {@code byte} array. |
123 | * | 121 | * |
124 | * @return the numeric value represented by this object after conversion to | 122 | * @return the numeric value represented by this object after conversion to |
125 | - * type {@code byte} array. | 123 | + * type {@code byte} array. |
126 | */ | 124 | */ |
127 | public byte[] toBytes() { | 125 | public byte[] toBytes() { |
128 | return Arrays.copyOf(this.address, this.address.length); | 126 | return Arrays.copyOf(this.address, this.address.length); |
... | @@ -132,7 +130,7 @@ public class MacAddress { | ... | @@ -132,7 +130,7 @@ public class MacAddress { |
132 | * Returns the value of the {@code MACAddress} as a {@code long}. | 130 | * Returns the value of the {@code MACAddress} as a {@code long}. |
133 | * | 131 | * |
134 | * @return the numeric value represented by this object after conversion to | 132 | * @return the numeric value represented by this object after conversion to |
135 | - * type {@code long}. | 133 | + * type {@code long}. |
136 | */ | 134 | */ |
137 | public long toLong() { | 135 | public long toLong() { |
138 | long mac = 0; | 136 | long mac = 0; |
... | @@ -169,6 +167,17 @@ public class MacAddress { | ... | @@ -169,6 +167,17 @@ public class MacAddress { |
169 | return (this.address[0] & 0x01) != 0; | 167 | return (this.address[0] & 0x01) != 0; |
170 | } | 168 | } |
171 | 169 | ||
170 | + /** | ||
171 | + * Returns true if this MAC address is link local. | ||
172 | + * | ||
173 | + * @return true if link local | ||
174 | + */ | ||
175 | + public boolean isLinkLocal() { | ||
176 | + return LL[0] == address[0] && LL[1] == address[1] && LL[2] == address[2] && | ||
177 | + LL[3] == address[3] && LL[4] == address[4] && | ||
178 | + (LL[5] == address[5] || LL[6] == address[5] || LL[7] == address[5]); | ||
179 | + } | ||
180 | + | ||
172 | @Override | 181 | @Override |
173 | public boolean equals(final Object o) { | 182 | public boolean equals(final Object o) { |
174 | if (o == this) { | 183 | if (o == this) { |
... | @@ -202,7 +211,7 @@ public class MacAddress { | ... | @@ -202,7 +211,7 @@ public class MacAddress { |
202 | 211 | ||
203 | /** | 212 | /** |
204 | * @return MAC address in string representation without colons (useful for | 213 | * @return MAC address in string representation without colons (useful for |
205 | - * radix tree storage) | 214 | + * radix tree storage) |
206 | */ | 215 | */ |
207 | public String toStringNoColon() { | 216 | public String toStringNoColon() { |
208 | final StringBuilder builder = new StringBuilder(); | 217 | final StringBuilder builder = new StringBuilder(); | ... | ... |
-
Please register or login to post a comment