/* * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.bgp.linkstate; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.util.Collections; import org.junit.Test; import org.opendaylight.protocol.bgp.linkstate.attribute.sr.SrNodeAttributesParser; import org.opendaylight.protocol.util.ByteArray; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.state.SrAlgorithm; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.state.SrAlgorithmBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.state.SrCapabilities; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.state.SrCapabilitiesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.rev150206.Algorithm; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.rev150206.SidLabel; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.rev150206.SrCapabilities.Flags; public class SrAttributeParserTest { @Test public void testSrAlgorithm() { final byte[] bytes = { 0 }; final SrAlgorithm alg = new SrAlgorithmBuilder().setAlgorithm(Lists.newArrayList(Algorithm.ShortestPathFirst)).build(); final SrAlgorithm empty = new SrAlgorithmBuilder().setAlgorithm(Collections.emptyList()).build(); assertEquals(alg, SrNodeAttributesParser.parseSrAlgorithms(Unpooled.wrappedBuffer(bytes))); final ByteBuf b = Unpooled.buffer(); assertEquals(empty, SrNodeAttributesParser.parseSrAlgorithms(b)); SrNodeAttributesParser.serializeSrAlgorithms(alg, b); assertArrayEquals(bytes, ByteArray.readAllBytes(b)); b.clear(); SrNodeAttributesParser.serializeSrAlgorithms(empty, b); assertEquals(0, b.readableBytes()); } @Test public void testSrCapabilities() { final byte[] bytes = { (byte)0xC0, 0, 0, 10, 1, 4, 1, 2, 3, 4 }; final SrCapabilities caps = new SrCapabilitiesBuilder().setFlags(new Flags(Boolean.TRUE, Boolean.TRUE)).setSid(new SidLabel(new byte[] {1,2,3,4})).setValueRange((long) 10).build(); assertEquals(caps, SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytes))); final ByteBuf b = Unpooled.buffer(); SrNodeAttributesParser.serializeSrCapabilities(caps, b); assertArrayEquals(bytes, ByteArray.readAllBytes(b)); } }