2 * Copyright (c) 2014 Contextream, 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
8 package org.opendaylight.lispflowmapping.serializer.address;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import java.nio.ByteBuffer;
14 import org.junit.Test;
15 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
16 import org.opendaylight.lispflowmapping.lisp.serializer.exception.LispSerializationException;
17 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.AfiListLcaf;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameAfi;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.DistinguishedNameType;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.AfiList;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedName;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.DistinguishedNameBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.EidBuilder;
27 public class DistinguishedNameSerializerTest extends BaseTestCase {
30 public void deserialize__EmptyString() throws Exception {
31 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 00"), null);
33 assertEquals(DistinguishedNameAfi.VALUE, address.getAddressType());
34 DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
36 assertEquals("", distinguishedName.getDistinguishedName().getValue());
40 public void deserialize__DavidString() throws Exception {
41 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 64 61 76 69 64 00"),
44 assertEquals(DistinguishedNameAfi.VALUE, address.getAddressType());
45 DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
47 assertEquals("david", distinguishedName.getDistinguishedName().getValue());
52 public void deserialize__inList() throws Exception {
53 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 "
55 + "00 11 64 61 76 69 64 00"), null);
57 assertEquals(AfiListLcaf.VALUE, address.getAddressType());
58 assertEquals("david", ((AfiList) address.getAddress()).getAfiList().getAddressList().iterator().next()
59 .getDistinguishedNameType().getValue());
63 @Test(expected = LispSerializationException.class)
64 public void deserialize__ShorterBuffer() throws Exception {
65 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("""
68 00 11 64 61 76 69 64 00"""), null);
71 @Test(expected = LispSerializationException.class)
72 public void deserialize__ShorterBuffer2() throws Exception {
73 LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("40 03 00 00 "
74 + "01 00 00 18 "), null);
78 public void deserialize__ReadUntilZero() throws Exception {
79 Eid address = LispAddressSerializer.getInstance().deserializeEid(hexToByteBuffer("00 11 64 61 76 00 69 64"),
82 DistinguishedName distinguishedName = (DistinguishedName) address.getAddress();
84 assertEquals("dav", distinguishedName.getDistinguishedName().getValue());
88 public void serialize__Simple() throws Exception {
89 EidBuilder eb = new EidBuilder();
90 eb.setAddressType(DistinguishedNameAfi.VALUE);
91 eb.setVirtualNetworkId(null);
92 eb.setAddress(new DistinguishedNameBuilder().setDistinguishedName(new DistinguishedNameType("david")).build());
94 ByteBuffer buf = ByteBuffer.allocate(LispAddressSerializer.getInstance().getAddressSize(eb.build()));
95 LispAddressSerializer.getInstance().serialize(buf, eb.build());
96 ByteBuffer expectedBuf = hexToByteBuffer("00 11 64 61 76 69 64 00");
97 assertArrayEquals(expectedBuf.array(), buf.array());