BUG-50 : fixed bugs for ERO EXRS subobject. 57/2257/1
authorDana Kutenicsova <dkutenic@cisco.com>
Tue, 29 Oct 2013 18:28:00 +0000 (19:28 +0100)
committerDana Kutenicsova <dkutenic@cisco.com>
Tue, 29 Oct 2013 18:28:40 +0000 (19:28 +0100)
Change-Id: I9226b765d6b0120cdebf66dd792e5bd47082b91c
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/object/AbstractXROWithSubobjectsParser.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/subobject/EROExplicitExclusionRouteSubobjectParser.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/PCEPEROSubobjectParserTest.java
rsvp/api/src/main/yang/rsvp.yang

index 89309c90608ef8554e7aa2b4fab827814adf4044..bc63d3f62067bebcac4beddf5e946ebf53385c12 100644 (file)
@@ -59,7 +59,8 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
 
                        length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
 
-                       type = bytes[offset + TYPE_FLAG_F_OFFSET];
+                       final boolean mandatory = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+                       type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
 
                        if (length > bytes.length - offset) {
                                throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
@@ -70,7 +71,7 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
                        System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
 
                        logger.debug("Attempt to parse subobject from bytes: {}", ByteArray.bytesToHexString(soContentsBytes));
-                       final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, false);
+                       final Subobjects sub = this.subobjReg.getSubobjectParser(type).parseSubobject(soContentsBytes, mandatory);
                        logger.debug("Subobject was parsed. {}", sub);
 
                        subs.add(sub);
@@ -94,7 +95,8 @@ public abstract class AbstractXROWithSubobjectsParser implements ObjectParser, O
 
                        final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
 
-                       final byte typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0]);
+                       final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
+                                       : 0));
                        final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
 
                        bytes[0] = typeBytes;
index 07c9826184773c81d135ef194a1b320d38c891b0..406de8620a6fc3d19b7c6b04c0b9dbe0d04255a2 100644 (file)
@@ -13,10 +13,13 @@ import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.Exrs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder;
 
 import com.google.common.collect.Lists;
 
@@ -47,15 +50,36 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
                }
                final SubobjectsBuilder builder = new SubobjectsBuilder();
                builder.setLoose(loose);
-               // builder.setSubobjectType( )
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> list = parseSubobjects(buffer);
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs> exrss = Lists.newArrayList();
+               for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects s : list) {
+                       final ExrsBuilder b = new ExrsBuilder();
+                       b.setAttribute(s.getAttribute());
+                       b.setMandatory(s.isMandatory());
+                       b.setSubobjectType(s.getSubobjectType());
+                       exrss.add(b.build());
+               }
+               builder.setSubobjectType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsBuilder().setExrs(
+                               exrss).build());
                return builder.build();
        }
 
        @Override
        public byte[] serializeSubobject(final Subobjects subobject) {
-
-               // return PCEPXROSubobjectParser.put(subobject.getXroSubobjets());
-               return new byte[0];
+               if (!(subobject.getSubobjectType() instanceof Exrs)) {
+                       throw new IllegalArgumentException("Unknown subobject instance. Passed " + subobject.getSubobjectType().getClass()
+                                       + ". Needed Exrs.");
+               }
+               final Exrs e = (Exrs) subobject.getSubobjectType();
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> list = Lists.newArrayList();
+               for (final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs ex : e.getExrs()) {
+                       final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.SubobjectsBuilder();
+                       b.setAttribute(ex.getAttribute());
+                       b.setMandatory(ex.isMandatory());
+                       b.setSubobjectType(ex.getSubobjectType());
+                       list.add(b.build());
+               }
+               return serializeSubobject(list);
        }
 
        private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects> parseSubobjects(
@@ -76,8 +100,8 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
 
                        length = ByteArray.bytesToInt(ByteArray.subByte(bytes, offset + LENGTH_F_OFFSET, SUB_LENGTH_F_LENGTH));
 
-                       type = bytes[offset + TYPE_FLAG_F_OFFSET];
-
+                       final boolean mandatory = ((bytes[offset + TYPE_FLAG_F_OFFSET] & (1 << 7)) != 0) ? true : false;
+                       type = (bytes[offset + TYPE_FLAG_F_OFFSET] & 0xff) & ~(1 << 7);
                        if (length > bytes.length - offset) {
                                throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= "
                                                + (bytes.length - offset));
@@ -86,10 +110,9 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
                        soContentsBytes = new byte[length - SO_CONTENTS_OFFSET];
                        System.arraycopy(bytes, offset + SO_CONTENTS_OFFSET, soContentsBytes, 0, length - SO_CONTENTS_OFFSET);
 
-                       final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects sub = this.registry.getSubobjectParser(
-                                       type).parseSubobject(soContentsBytes, false);
+                       final XROSubobjectParser parser = this.registry.getSubobjectParser(type);
 
-                       subs.add(sub);
+                       subs.add(parser.parseSubobject(soContentsBytes, mandatory));
 
                        offset += length;
                }
@@ -107,11 +130,14 @@ public class EROExplicitExclusionRouteSubobjectParser implements EROSubobjectPar
 
                        final XROSubobjectSerializer serializer = this.registry.getSubobjectSerializer(subobject);
 
+                       System.out.println(serializer);
+
                        final byte[] valueBytes = serializer.serializeSubobject(subobject);
 
                        final byte[] bytes = new byte[SUB_HEADER_LENGTH + valueBytes.length];
 
-                       final byte typeBytes = (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0]);
+                       final byte typeBytes = (byte) (ByteArray.cutBytes(ByteArray.intToBytes(serializer.getType()), (Integer.SIZE / 8) - 1)[0] | (subobject.isMandatory() ? 1 << 7
+                                       : 0));
                        final byte lengthBytes = ByteArray.cutBytes(ByteArray.intToBytes(valueBytes.length), (Integer.SIZE / 8) - 1)[0];
 
                        bytes[0] = typeBytes;
index 3273413858d43ffcc886cbb244fc739090e8b10f..66f4a35bd9023a45bc7703263c1db8134a1c946e 100644 (file)
@@ -10,10 +10,13 @@ package org.opendaylight.protocol.pcep.impl;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 
+import java.util.List;
+
 import org.junit.Test;
 import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
+import org.opendaylight.protocol.pcep.impl.subobject.EROExplicitExclusionRouteSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROLabelSubobjectParser;
 import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
@@ -30,8 +33,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.LabelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.ExrsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.label.type.GeneralizedLabelBuilder;
 
+import com.google.common.collect.Lists;
+
 public class PCEPEROSubobjectParserTest {
        private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
        private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
@@ -45,6 +51,7 @@ public class PCEPEROSubobjectParserTest {
                        (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) 0x80, (byte) 0x02, (byte) 0x12, (byte) 0x00, (byte) 0x25, (byte) 0xFF };
+       private static final byte[] exrsBytes = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 };
 
        @Test
        public void testEROIp4PrefixSubobject() throws PCEPDeserializerException {
@@ -117,7 +124,7 @@ public class PCEPEROSubobjectParserTest {
        }
 
        @Test
-       public void testEroLabelSubobject() throws Exception {
+       public void testEROLabelSubobject() throws Exception {
                final EROLabelSubobjectParser parser = new EROLabelSubobjectParser(PCEPExtensionProviderContextImpl.create().getLabelHandlerRegistry());
                final SubobjectsBuilder subs = new SubobjectsBuilder();
                subs.setLoose(true);
@@ -127,8 +134,18 @@ public class PCEPEROSubobjectParserTest {
                assertArrayEquals(labelBytes, parser.serializeSubobject(subs.build()));
        }
 
-       public void testEROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
-               // objsToTest.add(new EROExplicitExclusionRouteSubobject(Arrays.asList((ExcludeRouteSubobject) new
-               // XROAsNumberSubobject(new AsNumber((long) 2588), true))));
+       @Test
+       public void testEROEXRSSubobject() throws Exception {
+               final EROExplicitExclusionRouteSubobjectParser parser = new EROExplicitExclusionRouteSubobjectParser(PCEPExtensionProviderContextImpl.create().getXROSubobjectHandlerRegistry());
+               final SubobjectsBuilder subs = new SubobjectsBuilder();
+               subs.setLoose(true);
+               final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.Exrs> list = Lists.newArrayList();
+               final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.explicit.route.subobjects.subobject.type.exrs.ExrsBuilder();
+               builder.setMandatory(true);
+               builder.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
+               list.add(builder.build());
+               subs.setSubobjectType(new ExrsBuilder().setExrs(list).build());
+               assertEquals(subs.build(), parser.parseSubobject(exrsBytes, true));
+               // assertArrayEquals(exrsBytes, parser.serializeSubobject(subs.build()));
        }
 }
index 898409afa573410fcc18358beae9c0aee528079e..556ac16e47b33873212676639f67f3ce4671339d 100644 (file)
@@ -355,7 +355,7 @@ module rsvp {
                uses basic-explicit-route-subobjects {
                        augment "subobject-type" {
                                case exrs {
-                                       container exrs {
+                                       list exrs {
                                                uses exclude-route-subobjects;
                                        }
                                }