2 * Copyright (c) 2013 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.openflowplugin.openflow.md.util;
10 import java.math.BigInteger;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
19 public class InventoryDataServiceUtilTest {
22 * Test method for {@link InventoryDataServiceUtil#dataPathIdFromNodeId(NodeId)}.
25 public void testDataPathIdFromNodeId() {
26 String string = "openflow:";
27 NodeId[] nodeIds = new NodeId[] {
28 // 0x00000000 000004d2
29 new NodeId(string + "1234"),
30 // 0x8db2089e 01391a86
31 new NodeId(string + "10210232779920710278"),
32 // 0xffffffff ffffffff
33 new NodeId(string + "18446744073709551615"),
36 long[] expectedDPIDs = new long[] {
38 -8236511293788841338L,
42 for (int i = 0; i < nodeIds.length; i++) {
43 BigInteger datapathId = InventoryDataServiceUtil.dataPathIdFromNodeId(nodeIds[i] );
44 Assert.assertEquals(expectedDPIDs[i], datapathId.longValue());
49 * Test method for {@link InventoryDataServiceUtil#bigIntegerToPaddedHex(BigInteger)}.
52 public void testLongToPaddedHex() {
53 BigInteger[] dpids = new BigInteger[] {
54 // 0x00000000 000004d2
55 new BigInteger("1234"),
56 // 0x8db2089e 01391a86
57 new BigInteger("10210232779920710278"),
58 // 0xffffffff ffffffff
59 new BigInteger("18446744073709551615"),
62 String[] expectedPaddedHexes = new String[] {
68 for (int i = 0; i < dpids.length; i++) {
69 String datapathIdHex = InventoryDataServiceUtil.bigIntegerToPaddedHex(dpids[i]);
70 Assert.assertEquals(expectedPaddedHexes[i], datapathIdHex);