From caa794f15599d924601be34bc544328577b2d055 Mon Sep 17 00:00:00 2001 From: Dana Kutenicsova Date: Sun, 22 Jun 2014 19:00:51 +0200 Subject: [PATCH] Fixed length of LINK_PROTECTION_TYPE. BGP parses incorrectly parsed one-byte value of this field. Correct length of this field is 2B. Change-Id: I272aad323dc7e7d26cfa89d368028a4bbce9dcae Signed-off-by: Dana Kutenicsova --- .../linkstate/LinkstateAttributeParser.java | 4 +-- .../LinkstateAttributeParserTest.java | 25 ++++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java index 7caf6fcd40..b62b32315b 100644 --- a/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java +++ b/bgp/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParser.java @@ -210,9 +210,9 @@ public class LinkstateAttributeParser implements AttributeParser { LOG.debug("Parsed Metric {}", builder.getTeMetric()); break; case TlvCode.LINK_PROTECTION_TYPE: - final LinkProtectionType lpt = LinkProtectionType.forValue(UnsignedBytes.toInt(value[0])); + final LinkProtectionType lpt = LinkProtectionType.forValue(UnsignedBytes.toInt(value[1])); if (lpt == null) { - LOG.warn("Link Protection Type not recognized: {}", UnsignedBytes.toInt(value[0])); + LOG.warn("Link Protection Type not recognized: {}", UnsignedBytes.toInt(value[1])); break; } builder.setLinkProtection(lpt); diff --git a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java index 511b52e10d..0352d21470 100644 --- a/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java +++ b/bgp/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java @@ -40,21 +40,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult public class LinkstateAttributeParserTest { - private static final byte[] LINK_ATTR = new byte[] { (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2a, (byte) 0x2a, - (byte) 0x2a, (byte) 0x2a, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0x2b, (byte) 0x2b, (byte) 0x2b, (byte) 0x2b, - (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x41, - (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, (byte) 0x04, (byte) 0x42, (byte) 0x00, (byte) 0x04, - (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x04, (byte) 0x43, (byte) 0x00, (byte) 0x20, (byte) 0x46, (byte) 0x43, - (byte) 0x50, (byte) 0x00, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x04, (byte) 0x44, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x45, (byte) 0x00, - (byte) 0x01, (byte) 0x08, (byte) 0x04, (byte) 0x46, (byte) 0x00, (byte) 0x01, (byte) 0xc0, (byte) 0x04, (byte) 0x47, (byte) 0x00, - (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x04, (byte) 0x48, (byte) 0x00, (byte) 0x08, (byte) 0x12, (byte) 0x34, - (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70, (byte) 0x04, (byte) 0x4a, (byte) 0x00, (byte) 0x05, - (byte) 0x31, (byte) 0x32, (byte) 0x4b, (byte) 0x2d, (byte) 0x32, - - (byte) 0x04, (byte) 0x88, (byte) 0x00, (byte) 0x01, (byte) 0x0a }; + private static final byte[] LINK_ATTR = { 0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b, + 0x04, 0x40, 0, 0x04, 0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04, + 0x46, 0x43, 0x50, 0, 0x04, 0x43, 0, 0x20, 0x46, 0x43, 0x50, 0, 0x46, 0x43, 0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x44, 0, 0x08, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x45, 0, 0x02, 0, 0x08, 0x04, 0x46, 0, 0x01, + (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70, 0x04, 0x4a, + 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, (byte) 0x88, 0, 0x01, 0x0a }; private static final byte[] NODE_ATTR = new byte[] { (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x2a, (byte) 0x00, (byte) 0x2b, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0xb0, (byte) 0x04, (byte) 0x02, (byte) 0x00, @@ -91,9 +82,8 @@ public class LinkstateAttributeParserTest { assertNotNull(ls); assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue()); - assertEquals(new Long(10), ls.getMetric().getValue()); - assertEquals(new Long(0), ls.getAdminGroup().getValue()); assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue()); + assertEquals(new Long(0), ls.getAdminGroup().getValue()); assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 }, ls.getMaxLinkBandwidth().getValue()); assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 }, ls.getMaxReservableBandwidth().getValue()); assertNotNull(ls.getUnreservedBandwidth()); @@ -101,6 +91,7 @@ public class LinkstateAttributeParserTest { assertEquals(LinkProtectionType.Dedicated1to1, ls.getLinkProtection()); assertTrue(ls.getMplsProtocol().isLdp()); assertTrue(ls.getMplsProtocol().isRsvpte()); + assertEquals(new Long(10), ls.getMetric().getValue()); assertEquals(2, ls.getSharedRiskLinkGroups().size()); assertEquals(305419896, ls.getSharedRiskLinkGroups().get(0).getValue().intValue()); assertEquals("12K-2", ls.getLinkName()); -- 2.36.6