Merge into master from pull request #292:
Add a few new TLVs (https://github.com/floodlight/loxigen/pull/292)
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index dc803df..12d6260 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -506,6 +506,13 @@
error_cause_data = JType("OFErrorCauseData") \
.op(version=ANY, read="OFErrorCauseData.read(bb, $length, OFVersion.OF_$version)", write="$name.writeTo(bb)", default="OFErrorCauseData.NONE");
+var_string = JType('String').op(
+ read='ChannelUtils.readFixedLengthString(bb, $length)',
+ write='ChannelUtils.writeFixedLengthString(bb, $name, $name.length())',
+ default='""',
+ funnel='sink.putUnencodedChars($name)'
+ )
+
generic_t = JType("T")
@@ -686,6 +693,7 @@
'of_bsn_tlv_vlan_vid' : { 'value' : vlan_vid },
'of_bsn_table_set_buckets_size' : { 'table_id' : table_id },
'of_bsn_gentable_entry_add' : { 'table_id' : gen_table_id },
+ 'of_bsn_log': { 'data': var_string },
'of_features_reply' : { 'auxiliary_id' : of_aux_id},
}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java
index ba7eb93..7cd8099 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddressWithMask.java
@@ -1,5 +1,7 @@
package org.projectfloodlight.openflow.types;
+import com.google.common.base.Preconditions;
+
public abstract class IPAddressWithMask<F extends IPAddress<F>> extends Masked<F> {
@@ -8,6 +10,8 @@
}
public abstract IPVersion getIpVersion();
+
+ public abstract boolean contains(IPAddress<?> ip);
public F getSubnetBroadcastAddress() {
if (!mask.isCidrMask()) {
@@ -22,9 +26,8 @@
}
public static IPAddressWithMask<?> of(String ip) {
- if (ip == null) {
- throw new NullPointerException("String ip must not be null");
- }
+ Preconditions.checkNotNull(ip, "string ip must not be null");
+
if (ip.indexOf('.') != -1)
return IPv4AddressWithMask.of(ip);
else if (ip.indexOf(':') != -1)
@@ -49,5 +52,4 @@
return res.toString();
}
-
}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
index 865fb79..d398a85 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
@@ -6,6 +6,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
+import com.google.common.base.Preconditions;
import com.google.common.hash.PrimitiveSink;
import com.google.common.primitives.UnsignedInts;
@@ -78,19 +79,17 @@
@Override
public IPv4Address and(IPv4Address other) {
- if (other == null) {
- throw new NullPointerException("Other IP Address must not be null");
- }
- IPv4Address otherIp = (IPv4Address) other;
+ Preconditions.checkNotNull(other, "other must not be null");
+
+ IPv4Address otherIp = other;
return IPv4Address.of(rawValue & otherIp.rawValue);
}
@Override
public IPv4Address or(IPv4Address other) {
- if (other == null) {
- throw new NullPointerException("Other IP Address must not be null");
- }
- IPv4Address otherIp = (IPv4Address) other;
+ Preconditions.checkNotNull(other, "other must not be null");
+
+ IPv4Address otherIp = other;
return IPv4Address.of(rawValue | otherIp.rawValue);
}
@@ -100,9 +99,8 @@
}
public static IPv4Address of(final byte[] address) {
- if (address == null) {
- throw new NullPointerException("Address must not be null");
- }
+ Preconditions.checkNotNull(address, "address must not be null");
+
if (address.length != LENGTH) {
throw new IllegalArgumentException(
"Invalid byte array length for IPv4Address address: " + address.length);
@@ -135,9 +133,8 @@
*/
@Nonnull
public static IPv4Address of(@Nonnull final String string) throws IllegalArgumentException {
- if (string == null) {
- throw new NullPointerException("String must not be null");
- }
+ Preconditions.checkNotNull(string, "string must not be null");
+
int start = 0;
int shift = 24;
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java
index 9b60c6a..2d08e1a 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4AddressWithMask.java
@@ -1,5 +1,7 @@
package org.projectfloodlight.openflow.types;
+import com.google.common.base.Preconditions;
+
public class IPv4AddressWithMask extends IPAddressWithMask<IPv4Address> {
public final static IPv4AddressWithMask NONE = of(IPv4Address.NONE, IPv4Address.NONE);
@@ -22,19 +24,15 @@
}
public static IPv4AddressWithMask of(IPv4Address value, IPv4Address mask) {
- if (value == null) {
- throw new NullPointerException("Value must not be null");
- }
- if (mask == null) {
- throw new NullPointerException("Mask must not be null");
- }
+ Preconditions.checkNotNull(value, "value must not be null");
+ Preconditions.checkNotNull(mask, "mask must not be null");
+
return new IPv4AddressWithMask(value, mask);
}
public static IPv4AddressWithMask of(final String string) {
- if (string == null) {
- throw new NullPointerException("String must not be null");
- }
+ Preconditions.checkNotNull(string, "string must not be null");
+
int slashPos;
String ip = string;
int maskBits = 32;
@@ -81,4 +79,15 @@
}
}
+ @Override
+ public boolean contains(IPAddress<?> ip) {
+ Preconditions.checkNotNull(ip, "ip must not be null");
+
+ if(ip.getIpVersion() == IPVersion.IPv4) {
+ IPv4Address ipv4 = (IPv4Address) ip;
+ return this.matches(ipv4);
+ }
+
+ return false;
+ }
}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
index 83fb31a..dbf5a90 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
@@ -8,6 +8,7 @@
import org.jboss.netty.buffer.ChannelBuffer;
import org.projectfloodlight.openflow.exceptions.OFParseError;
+import com.google.common.base.Preconditions;
import com.google.common.hash.PrimitiveSink;
import com.google.common.primitives.Longs;
@@ -102,19 +103,17 @@
@Override
public IPv6Address and(IPv6Address other) {
- if (other == null) {
- throw new NullPointerException("Other IP Address must not be null");
- }
- IPv6Address otherIp = (IPv6Address) other;
+ Preconditions.checkNotNull(other, "other must not be null");
+
+ IPv6Address otherIp = other;
return IPv6Address.of((raw1 & otherIp.raw1), (raw2 & otherIp.raw2));
}
@Override
public IPv6Address or(IPv6Address other) {
- if (other == null) {
- throw new NullPointerException("Other IP Address must not be null");
- }
- IPv6Address otherIp = (IPv6Address) other;
+ Preconditions.checkNotNull(other, "other must not be null");
+
+ IPv6Address otherIp = other;
return IPv6Address.of((raw1 | otherIp.raw1), (raw2 | otherIp.raw2));
}
@@ -124,9 +123,8 @@
}
public static IPv6Address of(final byte[] address) {
- if (address == null) {
- throw new NullPointerException("Address must not be null");
- }
+ Preconditions.checkNotNull(address, "address must not be null");
+
if (address.length != LENGTH) {
throw new IllegalArgumentException(
"Invalid byte array length for IPv6 address: " + address.length);
@@ -187,9 +185,8 @@
*/
@Nonnull
public static IPv6Address of(@Nonnull final String string) throws IllegalArgumentException {
- if (string == null) {
- throw new NullPointerException("String must not be null");
- }
+ Preconditions.checkNotNull(string, "string must not be null");
+
IPv6Builder builder = new IPv6Builder();
String[] parts = colonPattern.split(string, -1);
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java
index 7259c7f..f015871 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6AddressWithMask.java
@@ -3,6 +3,8 @@
import java.math.BigInteger;
import java.util.Arrays;
+import com.google.common.base.Preconditions;
+
public class IPv6AddressWithMask extends IPAddressWithMask<IPv6Address> {
public final static IPv6AddressWithMask NONE = of(IPv6Address.NONE, IPv6Address.NONE);
@@ -16,20 +18,15 @@
}
public static IPv6AddressWithMask of(IPv6Address value, IPv6Address mask) {
- if (value == null) {
- throw new NullPointerException("Value must not be null");
- }
- if (mask == null) {
- throw new NullPointerException("Mask must not be null");
- }
+ Preconditions.checkNotNull(value, "value must not be null");
+ Preconditions.checkNotNull(mask, "mask must not be null");
return new IPv6AddressWithMask(value, mask);
}
public static IPv6AddressWithMask of(final String string) {
- if (string == null) {
- throw new NullPointerException("String must not be null");
- }
+ Preconditions.checkNotNull(string, "string must not be null");
+
int slashPos;
String ip = string;
int maskBits = 128;
@@ -88,5 +85,15 @@
}
}
+ @Override
+ public boolean contains(IPAddress<?> ip) {
+ Preconditions.checkNotNull(ip, "ip must not be null");
+ if(ip.getIpVersion() == IPVersion.IPv6) {
+ IPv6Address ipv6 = (IPv6Address) ip;
+ return this.matches(ipv6);
+ }
+
+ return false;
+ }
}
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java
index 865df75..cbab734 100644
--- a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java
@@ -1,6 +1,8 @@
package org.projectfloodlight.openflow.types;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.UnknownHostException;
@@ -64,4 +66,43 @@
}
}
+ @Test
+ public void testContains() {
+
+ // Test IPv4 Mask
+ IPAddressWithMask<?> mask = IPAddressWithMask.of("1.2.3.4/24");
+
+ IPAddress<?> validIp = IPAddress.of("1.2.3.5");
+ assertTrue(mask.contains(validIp));
+
+ IPAddress<?> invalidIp = IPAddress.of("1.2.5.5");
+ assertFalse(mask.contains(invalidIp));
+
+ IPAddress<?> invalidIpv6 = IPAddress.of("10:10::ffff");
+ assertFalse(mask.contains(invalidIpv6));
+
+ // Test IPv6 Mask
+ mask = IPAddressWithMask.of("10:10::1/112");
+
+ validIp = IPAddress.of("10:10::f");
+ assertTrue(mask.contains(validIp));
+
+ invalidIp = IPAddress.of("11:10::f");
+ assertFalse(mask.contains(invalidIp));
+
+ IPAddress<?> invalidIpv4 = IPAddress.of("10.0.0.1");
+ assertFalse(mask.contains(invalidIpv4));
+ }
+
+ @Test
+ public void testContainsException() {
+ try {
+ IPAddressWithMask<?> mask = IPAddressWithMask.of("1.2.3.4/24");
+ mask.contains(null);
+ fail("Should have thrown NullPointerException");
+ } catch (NullPointerException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+
}