3f0d73d005cc52eefafa14c939e48bcafc62a875
[bgpcep.git] / bgp / mvpn / src / test / java / org / opendaylight / protocol / bgp / mvpn / impl / nlri / SourceActiveADHandlerTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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
9 package org.opendaylight.protocol.bgp.mvpn.impl.nlri;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.util.ByteArray;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.NlriType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.SourceActiveADCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.mvpn.mvpn.choice.SourceActiveADCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mvpn.rev180417.source.active.a.d.grouping.SourceActiveADBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RdIpv4;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.RouteDistinguisher;
25
26 public final class SourceActiveADHandlerTest {
27     private static final byte[] SOURCE_ACTIVE = new byte[]{
28         0, 1, 1, 2, 3, 4, 1, 2,
29         32, 1, 0, 0, 1,
30         32, 2, 0, 0, 2,
31     };
32     private static final byte[] SOURCE_ACTIVE_LENGTH = new byte[]{
33         5, 18,
34         0, 1, 1, 2, 3, 4, 1, 2,
35         32, 1, 0, 0, 1,
36         32, 2, 0, 0, 2,
37     };
38
39     private final SourceActiveADCase expected = new SourceActiveADCaseBuilder()
40             .setSourceActiveAD(new SourceActiveADBuilder()
41                     .setRouteDistinguisher(new RouteDistinguisher(new RdIpv4("1.2.3.4:258")))
42                     .setMulticastSource(new IpAddress(new Ipv4Address("1.0.0.1")))
43                     .setMulticastGroup(new IpAddress(new Ipv4Address("2.0.0.2")))
44                     .build())
45             .build();
46     private final SourceActiveADHandler handler = new SourceActiveADHandler();
47
48     @Test
49     public void testParser() {
50         assertEquals(this.expected, this.handler.parseMvpn(Unpooled.copiedBuffer(SOURCE_ACTIVE)));
51     }
52
53     @Test
54     public void testSerializer() {
55         assertArrayEquals(SOURCE_ACTIVE_LENGTH, ByteArray.getAllBytes(this.handler.serializeMvpn(this.expected)));
56     }
57
58     @Test
59     public void testGetType() {
60         assertEquals(NlriType.SourceActiveAD.getIntValue(), this.handler.getType());
61     }
62
63     @Test
64     public void testGetClazz() {
65         assertEquals(SourceActiveADCase.class, this.handler.getClazz());
66     }
67 }