blob: e198e7d8f18f0fb877d52693fe8bbc9a994a24cb [file] [log] [blame]
Andrew Brownc46c1602015-02-18 10:45:56 -08001/*
2 * File name: FibEntryTest.java
3 *
4 * Purpose: Test encode/decode of FibEntry and NextHopRecord
5 *
6 * © Copyright Intel Corporation. All rights reserved.
7 * Intel Corporation, 2200 Mission College Boulevard,
8 * Santa Clara, CA 95052-8119, USA
9 */
10package com.intel.jndn.management;
11
12import com.intel.jndn.management.types.StatusDataset;
13import com.intel.jndn.management.types.NextHopRecord;
14import com.intel.jndn.management.types.FibEntry;
15import com.intel.jndn.utils.Client;
16import java.util.List;
17import junit.framework.Assert;
18import net.named_data.jndn.Data;
19import net.named_data.jndn.Face;
20import net.named_data.jndn.Interest;
21import net.named_data.jndn.Name;
22import net.named_data.jndn.encoding.EncodingException;
23import net.named_data.jndn.util.Blob;
24import static org.junit.Assert.assertEquals;
25import static org.junit.Assert.assertTrue;
26import org.junit.Test;
27
28/**
29 * Test encode/decode of FibEntry and NextHopRecord
30 *
31 * @author Andrew Brown <andrew.brown@intel.com>
32 */
33public class FibEntryTest {
34
Andrew Brown211d2b62015-02-18 11:12:02 -080035 /**
36 * Test encoding/decoding
37 *
38 * @throws java.lang.Exception
39 */
40 @Test
41 public void testEncodeDecode() throws Exception {
42 NextHopRecord nextHopRecord = new NextHopRecord();
43 nextHopRecord.setFaceId(42);
44 nextHopRecord.setCost(100);
45 FibEntry entry = new FibEntry();
46 entry.setName(new Name("/fib/entry/test"));
47 entry.getRecords().add(nextHopRecord);
Andrew Brownc46c1602015-02-18 10:45:56 -080048
Andrew Brown211d2b62015-02-18 11:12:02 -080049 // encode
50 Blob encoded = entry.wireEncode();
Andrew Brownc46c1602015-02-18 10:45:56 -080051
Andrew Brown211d2b62015-02-18 11:12:02 -080052 // decode
53 FibEntry decoded = new FibEntry();
54 decoded.wireDecode(encoded.buf());
Andrew Brownc46c1602015-02-18 10:45:56 -080055
Andrew Brown211d2b62015-02-18 11:12:02 -080056 // test
57 Assert.assertEquals(entry.getName().toUri(), decoded.getName().toUri());
58 Assert.assertEquals(entry.getRecords().get(0).getFaceId(), decoded.getRecords().get(0).getFaceId());
59 Assert.assertEquals(entry.getRecords().get(0).getCost(), decoded.getRecords().get(0).getCost());
60 }
Andrew Brownc46c1602015-02-18 10:45:56 -080061
Andrew Brown211d2b62015-02-18 11:12:02 -080062 /**
63 * Integration test to run on actual system
64 *
65 * @param args
66 * @throws EncodingException
67 */
68 public static void main(String[] args) throws Exception {
69 Face forwarder = new Face("localhost");
Andrew Brownc46c1602015-02-18 10:45:56 -080070
Andrew Brown211d2b62015-02-18 11:12:02 -080071 // build management Interest packet; see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
72 Interest interest = new Interest(new Name("/localhost/nfd/fib/list"));
73 interest.setMustBeFresh(true);
74 interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
75 interest.setInterestLifetimeMilliseconds(2000.0);
Andrew Brownc46c1602015-02-18 10:45:56 -080076
Andrew Brown211d2b62015-02-18 11:12:02 -080077 // send packet
78 Data data = Client.getDefault().getSync(forwarder, interest);
Andrew Brownc46c1602015-02-18 10:45:56 -080079
Andrew Brown211d2b62015-02-18 11:12:02 -080080 // decode results
81 List<FibEntry> results = StatusDataset.wireDecode(data.getContent(), FibEntry.class);
82 assertTrue(results.size() > 0);
83 assertEquals("/localhost/nfd", results.get(0).getName().toUri());
84 }
Andrew Brownc46c1602015-02-18 10:45:56 -080085}