Fix model names and imports
[bgpcep.git] / bgp / linkstate / src / test / java / org / opendaylight / protocol / bgp / linkstate / LinkstateAttributeParserTest.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.bgp.linkstate;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.fail;
14
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.PathAttributes1;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.LinkAttributes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.linkstate.path.attribute.link.state.attribute.NodeAttributes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
21
22 public class LinkstateAttributeParserTest {
23
24         private static final byte[] LINK_ATTR = new byte[] { (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x2a, (byte) 0x2a,
25                         (byte) 0x2a, (byte) 0x2a, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0x2b, (byte) 0x2b, (byte) 0x2b,
26                         (byte) 0x2b, (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
27                         (byte) 0x04, (byte) 0x41, (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, (byte) 0x04,
28                         (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x04, (byte) 0x43,
29                         (byte) 0x00, (byte) 0x20, (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00, (byte) 0x46, (byte) 0x43, (byte) 0x50,
30                         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
31                         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
32                         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x44,
33                         (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03,
34                         (byte) 0x00, (byte) 0x00, (byte) 0x0a };
35
36         private static final byte[] NODE_ATTR = new byte[] { (byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x05, (byte) 0x31, (byte) 0x32,
37                         (byte) 0x4b, (byte) 0x2d, (byte) 0x32, (byte) 0x04, (byte) 0x03, (byte) 0x00, (byte) 0x01, (byte) 0x72, (byte) 0x04,
38                         (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x29 };
39
40         private final LinkstateAttributeParser parser = new LinkstateAttributeParser();
41
42         @Test
43         public void testPositiveLinks() {
44                 final PathAttributesBuilder builder = new PathAttributesBuilder();
45                 try {
46                         this.parser.parseAttribute(LINK_ATTR, builder);
47                 } catch (final BGPParsingException e) {
48                         fail("No exception should occur.");
49                 }
50                 final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
51                 final LinkAttributes ls = (LinkAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
52                 assertNotNull(ls);
53
54                 assertEquals("42.42.42.42", ls.getLocalIpv4RouterId().getValue());
55                 assertEquals(new Long(10), ls.getMetric().getValue());
56                 assertEquals(new Long(0), ls.getAdminGroup().getValue());
57                 assertEquals("43.43.43.43", ls.getRemoteIpv4RouterId().getValue());
58                 assertArrayEquals(new byte[] { (byte) 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80 },
59                                 ls.getMaxLinkBandwidth().getValue());
60                 assertArrayEquals(new byte[] { (byte) 0x46, (byte) 0x43, (byte) 0x50, (byte) 0x00 },
61                                 ls.getMaxReservableBandwidth().getValue());
62                 assertNotNull(ls.getUnreservedBandwidth());
63                 assertEquals(8, ls.getUnreservedBandwidth().size());
64         }
65
66         @Test
67         public void testPositiveNodes() {
68                 final PathAttributesBuilder builder = new PathAttributesBuilder();
69                 try {
70                         this.parser.parseAttribute(NODE_ATTR, builder);
71                 } catch (final BGPParsingException e) {
72                         fail("No exception should occur.");
73                 }
74                 final PathAttributes1 attrs = builder.getAugmentation(PathAttributes1.class);
75                 final NodeAttributes ls = (NodeAttributes) attrs.getLinkstatePathAttribute().getLinkStateAttribute();
76                 assertNotNull(ls);
77
78                 assertEquals("12K-2", ls.getDynamicHostname());
79                 assertEquals(1, ls.getIsisAreaId().size());
80                 assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114 }, ls.getIsisAreaId().get(0).getValue());
81                 assertEquals("41.41.41.41", ls.getIpv4RouterId().getValue());
82         }
83 }