X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pcep%2Fimpl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fpcep%2Fimpl%2FPCEPEROSubobjectParserTest.java;h=1a6bc1aad8d3f5b431d00264960d08bf62d2d053;hb=bb1a5b0139b814666b85de460a89604bea5db0ec;hp=fa9fb16cf520cb5bdd5e2ec79940092ee080d905;hpb=cc3df352cb1591421c751913f07d8d3ce0b2a901;p=bgpcep.git diff --git a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java index fa9fb16cf5..1a6bc1aad8 100644 --- a/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java +++ b/pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java @@ -9,9 +9,11 @@ package org.opendaylight.protocol.pcep.impl; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import io.netty.buffer.Unpooled; import java.util.List; +import org.junit.Before; import org.junit.Test; import org.opendaylight.protocol.concepts.Ipv6Util; import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser; @@ -23,7 +25,7 @@ import org.opendaylight.protocol.pcep.impl.subobject.EROPathKey128SubobjectParse import org.opendaylight.protocol.pcep.impl.subobject.EROPathKey32SubobjectParser; import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser; import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException; -import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext; +import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix; @@ -50,22 +52,32 @@ import com.google.common.collect.Lists; public class PCEPEROSubobjectParserTest { private static final byte[] ip4PrefixBytes = { (byte) 0x81, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0x16, (byte) 0x00 }; + (byte) 0x16, (byte) 0x00 }; private static final byte[] ip6PrefixBytes = { (byte) 0x02, (byte) 0x14, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 }; + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 }; private static final byte[] asNumberBytes = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 }; private static final byte[] unnumberedBytes = { (byte) 0x84, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, - (byte) 0x50, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; + (byte) 0x50, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; private static final byte[] pathKey32Bytes = { (byte) 0xc0, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, - (byte) 0x50, (byte) 0x00 }; + (byte) 0x50, (byte) 0x00 }; private static final byte[] pathKey128Bytes = { (byte) 0xc1, (byte) 0x14, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, - (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; + (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; private static final byte[] labelBytes = { (byte) 0x83, (byte) 0x08, (byte) 0x80, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, - (byte) 0xFF }; + (byte) 0xFF }; private static final byte[] exrsBytes = { (byte) 0xa1, (byte) 0x06, (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 }; + private SimplePCEPExtensionProviderContext ctx; + private Activator act; + + @Before + public void setUp() { + this.ctx = new SimplePCEPExtensionProviderContext(); + this.act = new Activator(); + this.act.start(this.ctx); + } + @Test public void testEROIp4PrefixSubobject() throws PCEPDeserializerException { final EROIpv4PrefixSubobjectParser parser = new EROIpv4PrefixSubobjectParser(); @@ -73,7 +85,7 @@ public class PCEPEROSubobjectParserTest { subs.setLoose(true); subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix( new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(ip4PrefixBytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2)), true)); assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build())); } @@ -87,7 +99,7 @@ public class PCEPEROSubobjectParserTest { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build()).build()); subs.setLoose(false); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(ip6PrefixBytes, 2), false)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2)), false)); assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build())); } @@ -97,7 +109,7 @@ public class PCEPEROSubobjectParserTest { final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true); subs.setSubobjectType(new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(asNumberBytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(asNumberBytes, 2)), true)); assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build())); } @@ -108,7 +120,7 @@ public class PCEPEROSubobjectParserTest { subs.setLoose(true); subs.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered( new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(unnumberedBytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(unnumberedBytes, 2)), true)); assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build())); } @@ -121,7 +133,7 @@ public class PCEPEROSubobjectParserTest { pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 })); pBuilder.setPathKey(new PathKey(4660)); subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(pathKey32Bytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey32Bytes, 2)), true)); assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build())); } @@ -135,13 +147,14 @@ public class PCEPEROSubobjectParserTest { (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 })); pBuilder.setPathKey(new PathKey(4660)); subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(pathKey128Bytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(pathKey128Bytes, 2)), true)); assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build())); } @Test public void testEROLabelSubobject() throws Exception { - final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(ServiceLoaderPCEPExtensionProviderContext.create().getLabelHandlerRegistry()); + final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(this.ctx.getLabelHandlerRegistry()); + final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true); subs.setSubobjectType(new LabelCaseBuilder().setLabel( @@ -149,13 +162,13 @@ public class PCEPEROSubobjectParserTest { new GeneralizedLabelCaseBuilder().setGeneralizedLabel( new GeneralizedLabelBuilder().setGeneralizedLabel( new byte[] { (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF }).build()).build()).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(labelBytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(labelBytes, 2)), true)); assertArrayEquals(labelBytes, parser.serializeSubobject(subs.build())); } @Test public void testEROEXRSSubobject() throws Exception { - final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(ServiceLoaderPCEPExtensionProviderContext.create().getXROSubobjectHandlerRegistry()); + final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(this.ctx.getXROSubobjectHandlerRegistry()); final SubobjectBuilder subs = new SubobjectBuilder(); subs.setLoose(true); final List list = Lists.newArrayList(); @@ -164,7 +177,7 @@ public class PCEPEROSubobjectParserTest { builder.setSubobjectType(new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build()); list.add(builder.build()); subs.setSubobjectType(new ExrsCaseBuilder().setExrs(new ExrsBuilder().setExrs(list).build()).build()); - assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(exrsBytes, 2), true)); + assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(exrsBytes, 2)), true)); assertArrayEquals(exrsBytes, parser.serializeSubobject(subs.build())); } }