7c247b8762ef26bdb4312922bf103a9b695b7502
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / extended / communities / RouteOriginIpv4EcHandlerTest.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4Case;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4CaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.origin.ipv4._case.RouteOriginIpv4Builder;
22
23 public class RouteOriginIpv4EcHandlerTest {
24
25     private static final byte[] INPUT = {
26         12, 51, 2, 5, 0x15, 0x2d
27     };
28
29     @Test
30     public void testHandler() throws BGPDocumentedException, BGPParsingException {
31         final RouteOriginIpv4EcHandler handler = new RouteOriginIpv4EcHandler();
32         final RouteOriginIpv4Case expected = new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(
33                 new RouteOriginIpv4Builder()
34                     .setGlobalAdministrator(new Ipv4Address("12.51.2.5"))
35                     .setLocalAdministrator(5421)
36                     .build()).build();
37
38         final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT));
39         Assert.assertEquals(expected, exComm);
40
41         final ByteBuf output = Unpooled.buffer(INPUT.length);
42         handler.serializeExtendedCommunity(expected, output);
43         Assert.assertArrayEquals(INPUT, output.array());
44     }
45
46 }