blob: 1cd5897e05a103220793fa4996fabe10909e2fb1 [file] [log] [blame]
Andrew Brownc46c1602015-02-18 10:45:56 -08001/*
andrewsbrown7e6b9e82015-03-03 16:11:11 -08002 * jndn-management
3 * Copyright (c) 2015, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU Lesser General Public License,
7 * version 3, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
Andrew Brownc46c1602015-02-18 10:45:56 -080013 */
14package com.intel.jndn.management;
15
16import com.intel.jndn.management.types.StatusDataset;
17import com.intel.jndn.management.types.NextHopRecord;
18import com.intel.jndn.management.types.FibEntry;
andrewsbrown43b96302015-03-17 21:51:43 +010019import com.intel.jndn.utils.SimpleClient;
Andrew Brownc46c1602015-02-18 10:45:56 -080020import java.util.List;
21import junit.framework.Assert;
22import net.named_data.jndn.Data;
23import net.named_data.jndn.Face;
24import net.named_data.jndn.Interest;
25import net.named_data.jndn.Name;
26import net.named_data.jndn.encoding.EncodingException;
27import net.named_data.jndn.util.Blob;
28import static org.junit.Assert.assertEquals;
29import static org.junit.Assert.assertTrue;
30import org.junit.Test;
31
32/**
33 * Test encode/decode of FibEntry and NextHopRecord
34 *
35 * @author Andrew Brown <andrew.brown@intel.com>
36 */
37public class FibEntryTest {
38
Andrew Brown211d2b62015-02-18 11:12:02 -080039 /**
40 * Test encoding/decoding
41 *
42 * @throws java.lang.Exception
43 */
44 @Test
45 public void testEncodeDecode() throws Exception {
46 NextHopRecord nextHopRecord = new NextHopRecord();
47 nextHopRecord.setFaceId(42);
48 nextHopRecord.setCost(100);
49 FibEntry entry = new FibEntry();
50 entry.setName(new Name("/fib/entry/test"));
51 entry.getRecords().add(nextHopRecord);
Andrew Brownc46c1602015-02-18 10:45:56 -080052
Andrew Brown211d2b62015-02-18 11:12:02 -080053 // encode
54 Blob encoded = entry.wireEncode();
Andrew Brownc46c1602015-02-18 10:45:56 -080055
Andrew Brown211d2b62015-02-18 11:12:02 -080056 // decode
57 FibEntry decoded = new FibEntry();
58 decoded.wireDecode(encoded.buf());
Andrew Brownc46c1602015-02-18 10:45:56 -080059
Andrew Brown211d2b62015-02-18 11:12:02 -080060 // test
61 Assert.assertEquals(entry.getName().toUri(), decoded.getName().toUri());
62 Assert.assertEquals(entry.getRecords().get(0).getFaceId(), decoded.getRecords().get(0).getFaceId());
63 Assert.assertEquals(entry.getRecords().get(0).getCost(), decoded.getRecords().get(0).getCost());
64 }
Andrew Brownc46c1602015-02-18 10:45:56 -080065
Andrew Brown211d2b62015-02-18 11:12:02 -080066 /**
67 * Integration test to run on actual system
68 *
69 * @param args
70 * @throws EncodingException
71 */
72 public static void main(String[] args) throws Exception {
73 Face forwarder = new Face("localhost");
Andrew Brownc46c1602015-02-18 10:45:56 -080074
Andrew Brown211d2b62015-02-18 11:12:02 -080075 // build management Interest packet; see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
76 Interest interest = new Interest(new Name("/localhost/nfd/fib/list"));
77 interest.setMustBeFresh(true);
78 interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
79 interest.setInterestLifetimeMilliseconds(2000.0);
Andrew Brownc46c1602015-02-18 10:45:56 -080080
Andrew Brown211d2b62015-02-18 11:12:02 -080081 // send packet
andrewsbrown43b96302015-03-17 21:51:43 +010082 Data data = SimpleClient.getDefault().getSync(forwarder, interest);
Andrew Brownc46c1602015-02-18 10:45:56 -080083
Andrew Brown211d2b62015-02-18 11:12:02 -080084 // decode results
85 List<FibEntry> results = StatusDataset.wireDecode(data.getContent(), FibEntry.class);
86 assertTrue(results.size() > 0);
87 assertEquals("/localhost/nfd", results.get(0).getName().toUri());
88 }
Andrew Brownc46c1602015-02-18 10:45:56 -080089}