Rename lists such that they follow IETF conventions
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / PCEPXROSubobjectParserTest.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.Test;
14 import org.opendaylight.protocol.concepts.Ipv6Util;
15 import org.opendaylight.protocol.pcep.impl.subobject.XROAsNumberSubobjectParser;
16 import org.opendaylight.protocol.pcep.impl.subobject.XROIpv4PrefixSubobjectParser;
17 import org.opendaylight.protocol.pcep.impl.subobject.XROIpv6PrefixSubobjectParser;
18 import org.opendaylight.protocol.pcep.impl.subobject.XROPathKey128SubobjectParser;
19 import org.opendaylight.protocol.pcep.impl.subobject.XROPathKey32SubobjectParser;
20 import org.opendaylight.protocol.pcep.impl.subobject.XROSRLGSubobjectParser;
21 import org.opendaylight.protocol.pcep.impl.subobject.XROUnnumberedInterfaceSubobjectParser;
22 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
23 import org.opendaylight.protocol.util.ByteArray;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PceId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.PathKeyCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.subobject.subobject.type.path.key._case.PathKeyBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.ExcludeRouteSubobjects.Attribute;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.SrlgId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.SrlgCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.UnnumberedCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.as.number._case.AsNumberBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.srlg._case.SrlgBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.basic.explicit.route.subobjects.subobject.type.unnumbered._case.UnnumberedBuilder;
42
43 public class PCEPXROSubobjectParserTest {
44
45         private static final byte[] ip4PrefixBytes = { (byte) 0x01, (byte) 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
46                         (byte) 0x16, (byte) 0x00 };
47         private static final byte[] ip6PrefixBytes = { (byte) 0x82, (byte) 0x14, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
48                         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
49                         (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x16, (byte) 0x01 };
50         private static final byte[] srlgBytes = { (byte) 0xa2, (byte) 0x07, (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x02 };
51         private static final byte[] unnumberedBytes = { (byte) 0x84, (byte) 0x0c, (byte) 0x00, (byte) 0x01, (byte) 0x12, (byte) 0x34,
52                         (byte) 0x50, (byte) 0x00, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
53         private static final byte[] asNumberBytes = { (byte) 0xa0, (byte) 0x04, (byte) 0x00, (byte) 0x64 };
54         private static final byte[] pathKey32Bytes = { (byte) 0xc0, (byte) 0x08, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34,
55                         (byte) 0x50, (byte) 0x00 };
56         private static final byte[] pathKey128Bytes = { (byte) 0xc1, (byte) 0x14, (byte) 0x12, (byte) 0x34, (byte) 0x12, (byte) 0x34,
57                         (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE, (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00,
58                         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 };
59
60         @Test
61         public void testXROIp4PrefixSubobject() throws PCEPDeserializerException {
62                 final XROIpv4PrefixSubobjectParser parser = new XROIpv4PrefixSubobjectParser();
63                 final SubobjectBuilder subs = new SubobjectBuilder();
64                 subs.setMandatory(false);
65                 subs.setAttribute(Attribute.Interface);
66                 subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(
67                                 new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build());
68                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(ip4PrefixBytes, 2), false));
69                 assertArrayEquals(ip4PrefixBytes, parser.serializeSubobject(subs.build()));
70         }
71
72         @Test
73         public void testXROIp6PrefixSubobject() throws PCEPDeserializerException {
74                 final XROIpv6PrefixSubobjectParser parser = new XROIpv6PrefixSubobjectParser();
75                 final SubobjectBuilder subs = new SubobjectBuilder();
76                 subs.setMandatory(true);
77                 subs.setAttribute(Attribute.Node);
78                 subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(
79                                 new IpPrefixBuilder().setIpPrefix(
80                                                 new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
81                                                                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
82                                                                 (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build()).build());
83                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(ip6PrefixBytes, 2), true));
84                 assertArrayEquals(ip6PrefixBytes, parser.serializeSubobject(subs.build()));
85         }
86
87         @Test
88         public void testXROSrlgSubobject() throws PCEPDeserializerException {
89                 final XROSRLGSubobjectParser parser = new XROSRLGSubobjectParser();
90                 final SubobjectBuilder subs = new SubobjectBuilder();
91                 subs.setMandatory(true);
92                 subs.setAttribute(Attribute.Srlg);
93                 subs.setSubobjectType(new SrlgCaseBuilder().setSrlg(new SrlgBuilder().setSrlgId(new SrlgId(0x12345678L)).build()).build());
94                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(srlgBytes, 2), true));
95                 assertArrayEquals(srlgBytes, parser.serializeSubobject(subs.build()));
96         }
97
98         @Test
99         public void testXROUnnumberedSubobject() throws PCEPDeserializerException {
100                 final XROUnnumberedInterfaceSubobjectParser parser = new XROUnnumberedInterfaceSubobjectParser();
101                 final SubobjectBuilder subs = new SubobjectBuilder();
102                 subs.setMandatory(true);
103                 subs.setAttribute(Attribute.Node);
104                 subs.setSubobjectType(new UnnumberedCaseBuilder().setUnnumbered(
105                                 new UnnumberedBuilder().setRouterId(0x12345000L).setInterfaceId(0xffffffffL).build()).build());
106                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(unnumberedBytes, 2), true));
107                 assertArrayEquals(unnumberedBytes, parser.serializeSubobject(subs.build()));
108         }
109
110         @Test
111         public void testXROAsNumberSubobject() throws PCEPDeserializerException {
112                 final XROAsNumberSubobjectParser parser = new XROAsNumberSubobjectParser();
113                 final SubobjectBuilder subs = new SubobjectBuilder();
114                 subs.setMandatory(true);
115                 subs.setSubobjectType(new AsNumberCaseBuilder().setAsNumber(new AsNumberBuilder().setAsNumber(new AsNumber(0x64L)).build()).build());
116                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(asNumberBytes, 2), true));
117                 assertArrayEquals(asNumberBytes, parser.serializeSubobject(subs.build()));
118         }
119
120         @Test
121         public void testXROPathKey32Subobject() throws PCEPDeserializerException {
122                 final XROPathKey32SubobjectParser parser = new XROPathKey32SubobjectParser();
123                 final SubobjectBuilder subs = new SubobjectBuilder();
124                 subs.setMandatory(true);
125                 final PathKeyBuilder pBuilder = new PathKeyBuilder();
126                 pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x50, (byte) 0x00 }));
127                 pBuilder.setPathKey(new PathKey(4660));
128                 subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
129                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(pathKey32Bytes, 2), true));
130                 assertArrayEquals(pathKey32Bytes, parser.serializeSubobject(subs.build()));
131         }
132
133         @Test
134         public void testXROPathKey128Subobject() throws PCEPDeserializerException {
135                 final XROPathKey128SubobjectParser parser = new XROPathKey128SubobjectParser();
136                 final SubobjectBuilder subs = new SubobjectBuilder();
137                 subs.setMandatory(true);
138                 final PathKeyBuilder pBuilder = new PathKeyBuilder();
139                 pBuilder.setPceId(new PceId(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9A, (byte) 0xBC, (byte) 0xDE,
140                                 (byte) 0x12, (byte) 0x34, (byte) 0x54, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }));
141                 pBuilder.setPathKey(new PathKey(4660));
142                 subs.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
143                 assertEquals(subs.build(), parser.parseSubobject(ByteArray.cutBytes(pathKey128Bytes, 2), true));
144                 assertArrayEquals(pathKey128Bytes, parser.serializeSubobject(subs.build()));
145         }
146 }