2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.parser.impl.message.update;
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
14 import com.google.common.collect.Lists;
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.protocol.util.ByteArray;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ClusterIdBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
27 public class ClusterIdAttributeParserTest {
28 private static final byte[] clusterIdBytes = {(byte) 0x80, (byte) 0x0A, (byte) 0x08,
29 (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x1,
30 (byte) 0xC0, (byte) 0xA8, (byte) 0x1, (byte) 0x2};
31 ClusterIdAttributeParser parser;
35 this.parser = new ClusterIdAttributeParser();
39 public void testParserAttribute() throws Exception {
40 final List<ClusterIdentifier> list = Lists.newArrayList();
41 final Ipv4Address ip1 = new Ipv4Address("192.168.1.1");
42 final Ipv4Address ip2 = new Ipv4Address("192.168.1.2");
43 list.add(new ClusterIdentifier(ip1));
44 list.add(new ClusterIdentifier(ip2));
45 final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster
46 (list).build()).build();
49 final ByteBuf output = Unpooled.buffer();
50 this.parser.serializeAttribute(clusterId, output);
52 assertArrayEquals(clusterIdBytes, ByteArray.getAllBytes(output));
54 AttributesBuilder clusterIdOutput = new AttributesBuilder();
55 this.parser.parseAttribute(Unpooled.wrappedBuffer(ByteArray.cutBytes(clusterIdBytes, 3)), clusterIdOutput);
56 assertEquals(clusterId, clusterIdOutput.build());
60 public void testParseEmptyListAttribute() {
61 final List<ClusterIdentifier> list = Lists.newArrayList();
62 final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().setCluster
63 (list).build()).build();
64 final ByteBuf output = Unpooled.buffer();
65 this.parser.serializeAttribute(clusterId, output);
66 assertEquals(Unpooled.buffer(), output);
70 public void testParseEmptyAttribute() {
71 final Attributes clusterId = new AttributesBuilder().setClusterId(new ClusterIdBuilder().build()).build();
72 final ByteBuf output = Unpooled.buffer();
73 this.parser.serializeAttribute(clusterId, output);
74 assertEquals(Unpooled.buffer(), output);