a9e9570d1099655ac457a06b7560ee02216548bd
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPEROSubobjectParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
13 import org.junit.Ignore;
14 import org.junit.Test;
15 import org.opendaylight.protocol.concepts.Ipv6Util;
16 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
17 import org.opendaylight.protocol.pcep.impl.subobject.EROAsNumberSubobjectParser;
18 import org.opendaylight.protocol.pcep.impl.subobject.EROIpPrefixSubobjectParser;
19 import org.opendaylight.protocol.pcep.impl.subobject.EROPathKeySubobjectParser;
20 import org.opendaylight.protocol.pcep.impl.subobject.EROUnnumberedInterfaceSubobjectParser;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKeyBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedBuilder;
31
32 public class PCEPEROSubobjectParserTest {
33         private static final byte[] ip4PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
34         private static final byte[] ip6PrefixBytes = { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
35                         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
36                         (byte) 0xFF, (byte) 0x16, (byte) 0x00 };
37         private static final byte[] asNumberBytes = { (byte) 0x00, (byte) 0x64 };
38         private static final byte[] unnumberedBytes = { (byte) 0x00, (byte) 0x00, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00,
39                         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
40         private static final byte[] pathKey32Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 };
41         private static final byte[] pathKey128Bytes = { (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78,
42                         (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00,
43                         (byte) 0x00, (byte) 0x00, (byte) 0x00 };
44
45         @Test
46         public void testEROIp4PrefixSubobject() throws PCEPDeserializerException {
47                 final EROIpPrefixSubobjectParser parser = new EROIpPrefixSubobjectParser();
48                 final SubobjectsBuilder subs = new SubobjectsBuilder();
49                 subs.setLoose(true);
50                 subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build());
51                 assertEquals(subs.build(), parser.parseSubobject(ip4PrefixBytes, true));
52                 assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
53         }
54
55         @Test
56         public void testEROIp6PrefixSubobject() throws PCEPDeserializerException {
57                 final EROIpPrefixSubobjectParser parser = new EROIpPrefixSubobjectParser();
58                 final SubobjectsBuilder subs = new SubobjectsBuilder();
59                 subs.setSubobjectType(new IpPrefixBuilder().setIpPrefix(
60                                 new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
61                                                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
62                                                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build());
63                 subs.setLoose(false);
64                 assertEquals(subs.build(), parser.parseSubobject(ip6PrefixBytes, false));
65                 assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
66         }
67
68         @Test
69         public void testEROAsNumberSubobject() throws PCEPDeserializerException {
70                 final EROAsNumberSubobjectParser parser = new EROAsNumberSubobjectParser();
71                 final SubobjectsBuilder subs = new SubobjectsBuilder();
72                 subs.setLoose(true);
73                 subs.setSubobjectType(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build());
74                 assertEquals(subs.build(), parser.parseSubobject(asNumberBytes, true));
75                 assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build()));
76         }
77
78         @Test
79         public void testEROUnnumberedSubobject() throws PCEPDeserializerException {
80                 final EROUnnumberedInterfaceSubobjectParser parser = new EROUnnumberedInterfaceSubobjectParser();
81                 final SubobjectsBuilder subs = new SubobjectsBuilder();
82                 subs.setLoose(true);
83                 subs.setSubobjectType(new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build());
84                 assertEquals(subs.build(), parser.parseSubobject(unnumberedBytes, true));
85                 assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
86         }
87
88         @Test
89         public void testEROPathKey32Subobject() throws PCEPDeserializerException {
90                 final EROPathKeySubobjectParser parser = new EROPathKeySubobjectParser();
91                 final SubobjectsBuilder subs = new SubobjectsBuilder();
92                 subs.setLoose(true);
93                 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
94                 pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
95                 pBuilder.setPathKey(new PathKey(4660));
96                 subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
97                 assertEquals(subs.build(), parser.parseSubobject(pathKey32Bytes, true));
98                 assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
99         }
100
101         @Test
102         public void testEROPathKey128Subobject() throws PCEPDeserializerException {
103                 final EROPathKeySubobjectParser parser = new EROPathKeySubobjectParser();
104                 final SubobjectsBuilder subs = new SubobjectsBuilder();
105                 subs.setLoose(true);
106                 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder pBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.path.key.PathKeyBuilder();
107                 pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
108                                 (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
109                 pBuilder.setPathKey(new PathKey(4660));
110                 subs.setSubobjectType(new PathKeyBuilder().setPathKey(pBuilder.build()).build());
111                 assertEquals(subs.build(), parser.parseSubobject(pathKey128Bytes, true));
112                 assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
113         }
114
115         @Test
116         @Ignore
117         public void testEROSubojectsSerDeserWithoutBin() throws PCEPDeserializerException {
118                 // objsToTest.add(new EROType1LabelSubobject(0xFFFF51F2L, true, false));
119                 // objsToTest.add(new EROType1LabelSubobject(0x12345648L, false, true));
120                 // objsToTest.add(new EROWavebandSwitchingLabelSubobject(0x12345678L, 0x87654321L, 0xFFFFFFFFL, false, false));
121                 // objsToTest.add(new EROExplicitExclusionRouteSubobject(Arrays.asList((ExcludeRouteSubobject) new
122                 // XROAsNumberSubobject(new AsNumber((long) 2588), true))));
123         }
124 }