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
8 package org.opendaylight.protocol.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.MplsLabel;
18 public class MplsLabelUtilTest {
20 private static final long VAL1 = 5;
21 private static final byte[] VAL1_LEFT_BYTES = new byte[] { 0, 0, 0x50 };
22 private static final byte[] VAL1_LEFT_BYTES_BOTTOM = new byte[] { 0, 0, 0x51 };
25 public void testCreateLabel() {
26 assertEquals(new MplsLabel(VAL1), MplsLabelUtil
27 .mplsLabelForByteBuf(Unpooled.copiedBuffer(VAL1_LEFT_BYTES_BOTTOM)));
31 public void testBottomBit() {
32 assertFalse(MplsLabelUtil.getBottomBit(Unpooled.copiedBuffer(VAL1_LEFT_BYTES)));
33 assertTrue(MplsLabelUtil.getBottomBit(Unpooled.copiedBuffer(VAL1_LEFT_BYTES_BOTTOM)));
37 public void testSerialization() {
38 final MplsLabel label = new MplsLabel(VAL1);
39 assertEquals(Unpooled.copiedBuffer(VAL1_LEFT_BYTES), MplsLabelUtil.byteBufForMplsLabel(label));
40 assertEquals(Unpooled.copiedBuffer(VAL1_LEFT_BYTES_BOTTOM),
41 MplsLabelUtil.byteBufForMplsLabelWithBottomBit(label));