[ONOS-6169] Implement codec for multicast and list ext addresses
Change-Id: I784a893552fdc4eb798f4ccac38512a5d081b5ea
diff --git a/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/LispMappingExtensionCodecRegistrator.java b/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/LispMappingExtensionCodecRegistrator.java
index d41fd0c..99f3988 100644
--- a/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/LispMappingExtensionCodecRegistrator.java
+++ b/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/LispMappingExtensionCodecRegistrator.java
@@ -24,6 +24,8 @@
import org.onosproject.drivers.lisp.extensions.codec.LispAppDataAddressCodec;
import org.onosproject.drivers.lisp.extensions.codec.LispAsAddressCodec;
import org.onosproject.drivers.lisp.extensions.codec.LispGcAddressCodec;
+import org.onosproject.drivers.lisp.extensions.codec.LispListAddressCodec;
+import org.onosproject.drivers.lisp.extensions.codec.LispMulticastAddressCodec;
import org.onosproject.mapping.web.MappingCodecRegistrator;
import org.slf4j.Logger;
@@ -52,6 +54,8 @@
codecService.registerCodec(LispAppDataAddress.class, new LispAppDataAddressCodec());
codecService.registerCodec(LispAsAddress.class, new LispAsAddressCodec());
codecService.registerCodec(LispGcAddress.class, new LispGcAddressCodec());
+ codecService.registerCodec(LispListAddress.class, new LispListAddressCodec());
+ codecService.registerCodec(LispMulticastAddress.class, new LispMulticastAddressCodec());
log.info("Started");
}
@@ -61,6 +65,8 @@
codecService.unregisterCodec(LispAppDataAddress.class);
codecService.unregisterCodec(LispAsAddress.class);
codecService.unregisterCodec(LispGcAddress.class);
+ codecService.unregisterCodec(LispListAddress.class);
+ codecService.unregisterCodec(LispMulticastAddress.class);
registrator.deactivate();
registrator = null;
diff --git a/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/codec/LispListAddressCodec.java b/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/codec/LispListAddressCodec.java
new file mode 100644
index 0000000..4e5c197
--- /dev/null
+++ b/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/codec/LispListAddressCodec.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.drivers.lisp.extensions.codec;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.drivers.lisp.extensions.LispListAddress;
+import org.onosproject.mapping.addresses.MappingAddress;
+import org.slf4j.Logger;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * LISP list address codec.
+ */
+public final class LispListAddressCodec extends JsonCodec<LispListAddress> {
+
+ private final Logger log = getLogger(getClass());
+
+ protected static final String IPV4 = "ipv4";
+ protected static final String IPV6 = "ipv6";
+
+ private static final String MISSING_MEMBER_MESSAGE =
+ " member is required in LispListAddress";
+
+ @Override
+ public ObjectNode encode(LispListAddress address, CodecContext context) {
+ checkNotNull(address, "LispListAddress cannot be null");
+
+ final ObjectNode result = context.mapper().createObjectNode();
+
+ final JsonCodec<MappingAddress> addressCodec =
+ context.codec(MappingAddress.class);
+
+ if (address.getIpv4() != null) {
+ ObjectNode ipv4Node = addressCodec.encode(address.getIpv4(), context);
+ result.set(IPV4, ipv4Node);
+ }
+
+ if (address.getIpv6() != null) {
+ ObjectNode ipv6Node = addressCodec.encode(address.getIpv6(), context);
+ result.set(IPV6, ipv6Node);
+ }
+
+ if (address.getIpv4() == null && address.getIpv6() == null) {
+ log.error("Either IPv4 or IPv6 address should be specified.");
+ }
+
+ return result;
+ }
+
+ @Override
+ public LispListAddress decode(ObjectNode json, CodecContext context) {
+ if (json == null || !json.isObject()) {
+ return null;
+ }
+
+ final JsonCodec<MappingAddress> addressCodec =
+ context.codec(MappingAddress.class);
+ ObjectNode ipv4Json = get(json, IPV4);
+ ObjectNode ipv6Json = get(json, IPV6);
+ MappingAddress ipv4Address = null;
+ MappingAddress ipv6Address = null;
+
+ if (ipv4Json != null) {
+ ipv4Address = addressCodec.decode(ipv4Json, context);
+ }
+
+ if (ipv6Json != null) {
+ ipv6Address = addressCodec.decode(ipv6Json, context);
+ }
+
+ if (ipv4Json == null && ipv6Json == null) {
+ log.error("Either IPv4 or IPv6 address should be specified.");
+ }
+
+ return new LispListAddress.Builder()
+ .withIpv4(ipv4Address)
+ .withIpv6(ipv6Address)
+ .build();
+ }
+}
diff --git a/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddressCodec.java b/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddressCodec.java
new file mode 100644
index 0000000..f5a1efa
--- /dev/null
+++ b/drivers/lisp/src/main/java/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddressCodec.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.drivers.lisp.extensions.codec;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.drivers.lisp.extensions.LispMulticastAddress;
+import org.onosproject.mapping.addresses.MappingAddress;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onlab.util.Tools.nullIsIllegal;
+
+/**
+ * LISP multicast address codec.
+ */
+public final class LispMulticastAddressCodec extends JsonCodec<LispMulticastAddress> {
+
+ protected static final String INSTANCE_ID = "instanceId";
+ protected static final String SRC_MASK_LENGTH = "srcMaskLength";
+ protected static final String GRP_MASK_LENGTH = "grpMaskLength";
+ protected static final String SRC_ADDRESS = "srcAddress";
+ protected static final String GRP_ADDRESS = "grpAddress";
+
+ private static final String MISSING_MEMBER_MESSAGE =
+ " member is required in LispMulticastAddress";
+
+ @Override
+ public ObjectNode encode(LispMulticastAddress address, CodecContext context) {
+ checkNotNull(address, "LispMulticastAddress cannot be null");
+
+ final ObjectNode result = context.mapper().createObjectNode()
+ .put(INSTANCE_ID, address.getInstanceId())
+ .put(SRC_MASK_LENGTH, address.getSrcMaskLength())
+ .put(GRP_MASK_LENGTH, address.getGrpMaskLength());
+
+ final JsonCodec<MappingAddress> addressCodec =
+ context.codec(MappingAddress.class);
+
+ if (address.getSrcAddress() != null) {
+ ObjectNode srcAddressNode = addressCodec.encode(address.getSrcAddress(), context);
+ result.set(SRC_ADDRESS, srcAddressNode);
+ }
+
+ if (address.getGrpAddress() != null) {
+ ObjectNode grpAddressNode = addressCodec.encode(address.getGrpAddress(), context);
+ result.set(GRP_ADDRESS, grpAddressNode);
+ }
+
+ return result;
+ }
+
+ @Override
+ public LispMulticastAddress decode(ObjectNode json, CodecContext context) {
+ if (json == null || !json.isObject()) {
+ return null;
+ }
+
+ int instanceId = nullIsIllegal(json.get(INSTANCE_ID),
+ INSTANCE_ID + MISSING_MEMBER_MESSAGE).asInt();
+ byte srcMaskLength = (byte) nullIsIllegal(json.get(SRC_MASK_LENGTH),
+ SRC_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
+ byte grpMaskLength = (byte) nullIsIllegal(json.get(GRP_MASK_LENGTH),
+ GRP_MASK_LENGTH + MISSING_MEMBER_MESSAGE).asInt();
+
+ final JsonCodec<MappingAddress> addressCodec =
+ context.codec(MappingAddress.class);
+ ObjectNode srcAddressJson = get(json, SRC_ADDRESS);
+ MappingAddress srcAddress = null;
+
+ if (srcAddressJson != null) {
+ srcAddress = addressCodec.decode(srcAddressJson, context);
+ }
+
+ ObjectNode grpAddressJson = get(json, GRP_ADDRESS);
+ MappingAddress grpAddress = null;
+
+ if (grpAddressJson != null) {
+ grpAddress = addressCodec.decode(grpAddressJson, context);
+ }
+
+ return new LispMulticastAddress.Builder()
+ .withInstanceId(instanceId)
+ .withSrcMaskLength(srcMaskLength)
+ .withGrpMaskLength(grpMaskLength)
+ .withSrcAddress(srcAddress)
+ .withGrpAddress(grpAddress)
+ .build();
+ }
+}
diff --git a/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispAsAddressCodecTest.java b/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispAsAddressCodecTest.java
index 191b27e..1b1f17b 100644
--- a/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispAsAddressCodecTest.java
+++ b/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispAsAddressCodecTest.java
@@ -162,7 +162,7 @@
JsonNode json = context.mapper().readTree(jsonStream);
assertThat("JSON string should not be null", json, notNullValue());
LispAsAddress asAddress = asAddressCodec.decode((ObjectNode) json, context);
- assertThat("Decoded address should not be null", asAddress, notNullValue());
+ assertThat("decoded address should not be null", asAddress, notNullValue());
return asAddress;
}
}
diff --git a/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispListAddressCodecTest.java b/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispListAddressCodecTest.java
new file mode 100644
index 0000000..0a3f0a1
--- /dev/null
+++ b/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispListAddressCodecTest.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.drivers.lisp.extensions.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.codec.impl.CodecManager;
+import org.onosproject.drivers.lisp.extensions.LispListAddress;
+import org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator;
+import org.onosproject.mapping.addresses.MappingAddresses;
+import org.onosproject.mapping.web.codec.MappingAddressJsonMatcher;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+/**
+ * Unit tests for LispListAddressCodec.
+ */
+public class LispListAddressCodecTest {
+
+ private static final IpPrefix IPV4_PREFIX = IpPrefix.valueOf("10.1.1.0/24");
+ private static final IpPrefix IPV6_PREFIX = IpPrefix.valueOf("fe80::/64");
+
+ private CodecContext context;
+ private JsonCodec<LispListAddress> listAddressCodec;
+ private LispMappingExtensionCodecRegistrator registrator;
+
+ /**
+ * Sets up for each test.
+ * Creates a context and fetches the LispListAddress codec.
+ */
+ @Before
+ public void setUp() {
+ CodecManager manager = new CodecManager();
+ registrator = new LispMappingExtensionCodecRegistrator();
+ registrator.codecService = manager;
+ registrator.activate();
+
+ context = new LispMappingExtensionCodecContextAdapter(registrator.codecService);
+ listAddressCodec = context.codec(LispListAddress.class);
+ assertThat("List address codec should not be null",
+ listAddressCodec, notNullValue());
+ }
+
+ /**
+ * Deactivates the codec registrator.
+ */
+ @After
+ public void tearDown() {
+ registrator.deactivate();
+ }
+
+ /**
+ * Tests encoding of a LispListAddress object.
+ */
+ @Test
+ public void testLispListAddressEncode() {
+ LispListAddress address = new LispListAddress.Builder()
+ .withIpv4(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX))
+ .withIpv6(MappingAddresses.ipv6MappingAddress(IPV6_PREFIX))
+ .build();
+ ObjectNode addressJson = listAddressCodec.encode(address, context);
+ assertThat("errors in encoding List address JSON",
+ addressJson, LispListAddressJsonMatcher.matchesListAddress(address));
+ }
+
+ /**
+ * Tests decoding of a LispListAddress JSON object.
+ */
+ @Test
+ public void testLispListAddressDecode() throws IOException {
+ LispListAddress address = getLispListAddress("LispListAddress.json");
+
+ assertThat("incorrect IPv4 address", address.getIpv4(),
+ is(MappingAddresses.ipv4MappingAddress(IPV4_PREFIX)));
+ assertThat("incorrect IPv6 address", address.getIpv6(),
+ is(MappingAddresses.ipv6MappingAddress(IPV6_PREFIX)));
+ }
+
+ /**
+ * Hamcrest matcher for LispListAddress.
+ */
+ public static final class LispListAddressJsonMatcher
+ extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+ private final LispListAddress address;
+
+ /**
+ * Default constructor.
+ *
+ * @param address LispListAddress object
+ */
+ private LispListAddressJsonMatcher(LispListAddress address) {
+ this.address = address;
+ }
+
+ @Override
+ protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+ // check ipv4
+ MappingAddressJsonMatcher ipv4Matcher =
+ MappingAddressJsonMatcher.matchesMappingAddress(address.getIpv4());
+
+ // check ipv6
+ MappingAddressJsonMatcher ipv6Matcher =
+ MappingAddressJsonMatcher.matchesMappingAddress(address.getIpv6());
+
+ return ipv4Matcher.matches(jsonNode.get(LispListAddressCodec.IPV4)) ||
+ ipv6Matcher.matches(jsonNode.get(LispListAddressCodec.IPV6));
+
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(address.toString());
+ }
+
+ /**
+ * Factory to allocate a LispListAddress matcher.
+ *
+ * @param address LispListAddress object we are looking for
+ * @return matcher
+ */
+ public static LispListAddressJsonMatcher matchesListAddress(LispListAddress address) {
+ return new LispListAddressJsonMatcher(address);
+ }
+ }
+
+ /**
+ * Reads in a LispListAddress from the given resource and decodes it.
+ *
+ * @param resourceName resource to use to read the JSON for the rule
+ * @return decoded LispListAddress
+ * @throws IOException if processing the resource fails
+ */
+ private LispListAddress getLispListAddress(String resourceName) throws IOException {
+ InputStream jsonStream = LispListAddressCodecTest.class.getResourceAsStream(resourceName);
+ JsonNode json = context.mapper().readTree(jsonStream);
+ assertThat("JSON string should not be null", json, notNullValue());
+ LispListAddress listAddress = listAddressCodec.decode((ObjectNode) json, context);
+ assertThat("decoded address should not be null", listAddress, notNullValue());
+ return listAddress;
+ }
+}
diff --git a/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddressCodecTest.java b/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddressCodecTest.java
new file mode 100644
index 0000000..488494c
--- /dev/null
+++ b/drivers/lisp/src/test/java/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddressCodecTest.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.drivers.lisp.extensions.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpPrefix;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.codec.impl.CodecManager;
+import org.onosproject.drivers.lisp.extensions.LispMappingExtensionCodecRegistrator;
+import org.onosproject.drivers.lisp.extensions.LispMulticastAddress;
+import org.onosproject.mapping.addresses.MappingAddresses;
+import org.onosproject.mapping.web.codec.MappingAddressJsonMatcher;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+/**
+ * Unit tests for LispMulticastAddressCodec.
+ */
+public class LispMulticastAddressCodecTest {
+
+ private static final int INSTANCE_ID = 1;
+ private static final byte SRC_MASK_LENGTH = 2;
+ private static final byte GRP_MASK_LENGTH = 3;
+
+ private static final IpPrefix SRC_ADDRESS_PREFIX = IpPrefix.valueOf("10.1.1.0/24");
+ private static final IpPrefix GRP_ADDRESS_PREFIX = IpPrefix.valueOf("10.1.1.0/24");
+
+ private CodecContext context;
+ private JsonCodec<LispMulticastAddress> multicastAddressCodec;
+ private LispMappingExtensionCodecRegistrator registrator;
+
+ /**
+ * Sets up for each test.
+ * Creates a context and fetches the LispMulticastAddress codec.
+ */
+ @Before
+ public void setUp() {
+ CodecManager manager = new CodecManager();
+ registrator = new LispMappingExtensionCodecRegistrator();
+ registrator.codecService = manager;
+ registrator.activate();
+
+ context = new LispMappingExtensionCodecContextAdapter(registrator.codecService);
+ multicastAddressCodec = context.codec(LispMulticastAddress.class);
+ assertThat("Multicast address codec should not be null",
+ multicastAddressCodec, notNullValue());
+ }
+
+ /**
+ * Deactivates the codec registrator.
+ */
+ @After
+ public void tearDown() {
+ registrator.deactivate();
+ }
+
+ /**
+ * Tests encoding of a LispMulticastAddress object.
+ */
+ @Test
+ public void testLispMulticastAddressEncode() {
+ LispMulticastAddress address = new LispMulticastAddress.Builder()
+ .withInstanceId(INSTANCE_ID)
+ .withSrcMaskLength(SRC_MASK_LENGTH)
+ .withGrpMaskLength(GRP_MASK_LENGTH)
+ .withSrcAddress(MappingAddresses.ipv4MappingAddress(SRC_ADDRESS_PREFIX))
+ .withGrpAddress(MappingAddresses.ipv4MappingAddress(GRP_ADDRESS_PREFIX))
+ .build();
+ ObjectNode addressJson = multicastAddressCodec.encode(address, context);
+ assertThat("errors in encoding Multicast address JSON",
+ addressJson, LispMulticastAddressJsonMatcher.matchesMulticastAddress(address));
+ }
+
+ /**
+ * Tests decoding of a LispMulticastAddress JSON object.
+ */
+ @Test
+ public void testLispMulticastAddressDecode() throws IOException {
+ LispMulticastAddress address =
+ getLispMulticastAddress("LispMulticastAddress.json");
+
+ assertThat("incorrect instance id",
+ address.getInstanceId(), is(INSTANCE_ID));
+ assertThat("incorrect srcMaskLength",
+ address.getSrcMaskLength(), is(SRC_MASK_LENGTH));
+ assertThat("incorrect srcAddress", address.getSrcAddress(),
+ is(MappingAddresses.ipv4MappingAddress(SRC_ADDRESS_PREFIX)));
+ assertThat("incorrect grpMaskLength",
+ address.getGrpMaskLength(), is(GRP_MASK_LENGTH));
+ assertThat("incorrect grpAddress", address.getGrpAddress(),
+ is(MappingAddresses.ipv4MappingAddress(GRP_ADDRESS_PREFIX)));
+ }
+
+ /**
+ * Hamcrest matcher for LispMulticastAddress.
+ */
+ public static final class LispMulticastAddressJsonMatcher
+ extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+ private final LispMulticastAddress address;
+
+ /**
+ * Default constructor.
+ *
+ * @param address LispMulticastAddres object
+ */
+ private LispMulticastAddressJsonMatcher(LispMulticastAddress address) {
+ this.address = address;
+ }
+
+ @Override
+ protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+
+ // check instance id
+ int jsonInstanceId = jsonNode.get(LispMulticastAddressCodec.INSTANCE_ID).asInt();
+ int instanceId = address.getInstanceId();
+ if (jsonInstanceId != instanceId) {
+ description.appendText("Instance id was " + jsonInstanceId);
+ return false;
+ }
+
+ // check source mask length
+ byte jsonSrcMaskLength = (byte) jsonNode.get(
+ LispMulticastAddressCodec.SRC_MASK_LENGTH).asInt();
+ byte srcMaskLength = address.getSrcMaskLength();
+ if (jsonSrcMaskLength != srcMaskLength) {
+ description.appendText("SrcMaskLength was " + jsonSrcMaskLength);
+ return false;
+ }
+
+ // check group mask length
+ byte jsonGrpMaskLength = (byte) jsonNode.get(
+ LispMulticastAddressCodec.GRP_MASK_LENGTH).asInt();
+ byte grpMaskLength = address.getGrpMaskLength();
+ if (jsonGrpMaskLength != grpMaskLength) {
+ description.appendText("GrpMaskLength was " + jsonGrpMaskLength);
+ return false;
+ }
+
+ // check source address
+ MappingAddressJsonMatcher srcAddressMatcher =
+ MappingAddressJsonMatcher.matchesMappingAddress(address.getSrcAddress());
+
+ // check group address
+ MappingAddressJsonMatcher grpAddressMatcher =
+ MappingAddressJsonMatcher.matchesMappingAddress(address.getGrpAddress());
+
+ return srcAddressMatcher.matches(jsonNode.get(LispMulticastAddressCodec.SRC_ADDRESS)) ||
+ grpAddressMatcher.matches(jsonNode.get(LispMulticastAddressCodec.GRP_ADDRESS));
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(address.toString());
+ }
+
+ /**
+ * Factory to allocate a LispMulticastAddress matcher.
+ *
+ * @param address LispMulticastAddress object we are looking for
+ * @return matcher
+ */
+ public static LispMulticastAddressJsonMatcher matchesMulticastAddress(
+ LispMulticastAddress address) {
+ return new LispMulticastAddressJsonMatcher(address);
+ }
+ }
+
+ /**
+ * Reads in a LispMulticastAddress from the given resource and decodes it.
+ *
+ * @param resourceName resource to use to read the JSON for the rule
+ * @return decoded LispMulticastAddress
+ * @throws IOException if processing the resource fails
+ */
+ private LispMulticastAddress getLispMulticastAddress(String resourceName) throws IOException {
+ InputStream jsonStream = LispMulticastAddressCodecTest.class.getResourceAsStream(resourceName);
+ JsonNode json = context.mapper().readTree(jsonStream);
+ assertThat("JSON string should not be null", json, notNullValue());
+ LispMulticastAddress multicastAddress = multicastAddressCodec.decode((ObjectNode) json, context);
+ assertThat("decoded address should not be null", multicastAddress, notNullValue());
+ return multicastAddress;
+ }
+}
diff --git a/drivers/lisp/src/test/resources/org/onosproject/drivers/lisp/extensions/codec/LispListAddress.json b/drivers/lisp/src/test/resources/org/onosproject/drivers/lisp/extensions/codec/LispListAddress.json
new file mode 100644
index 0000000..3f92216
--- /dev/null
+++ b/drivers/lisp/src/test/resources/org/onosproject/drivers/lisp/extensions/codec/LispListAddress.json
@@ -0,0 +1,10 @@
+{
+ "ipv4": {
+ "type": "IPV4",
+ "ipv4": "10.1.1.0/24"
+ },
+ "ipv6": {
+ "type": "IPV6",
+ "ipv6": "fe80::/64"
+ }
+}
\ No newline at end of file
diff --git a/drivers/lisp/src/test/resources/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddress.json b/drivers/lisp/src/test/resources/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddress.json
new file mode 100644
index 0000000..94a37e6
--- /dev/null
+++ b/drivers/lisp/src/test/resources/org/onosproject/drivers/lisp/extensions/codec/LispMulticastAddress.json
@@ -0,0 +1,13 @@
+{
+ "instanceId": 1,
+ "srcMaskLength": 2,
+ "grpMaskLength": 3,
+ "srcAddress": {
+ "type": "IPV4",
+ "ipv4": "10.1.1.0/24"
+ },
+ "grpAddress": {
+ "type": "IPV4",
+ "ipv4": "10.1.1.0/24"
+ }
+}
\ No newline at end of file