blob: 96dd70be6e51ef13627395527486507128b53745 [file] [log] [blame]
Andrew Brownc46c1602015-02-18 10:45:56 -08001/*
2 * File name: RibEntryTest.java
3 *
4 * Purpose: Test encoding/decoding for RibEntry.
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.RibEntry;
14import com.intel.jndn.management.types.Route;
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 encoding/decoding for RibEntry.
30 *
31 * @author Andrew Brown <andrew.brown@intel.com>
32 */
33public class RibEntryTest {
34
35 /**
36 * Test encoding/decoding
37 *
38 * @throws java.lang.Exception
39 */
40 @Test
41 public void testEncodeDecode() throws Exception {
42 Route route = new Route();
43 route.setFaceId(42);
44 route.setCost(100);
45 route.setOrigin(0);
46 RibEntry entry = new RibEntry();
47 entry.setName(new Name("/rib/entry/test"));
48 entry.getRoutes().add(route);
49
50 // encode
51 Blob encoded = entry.wireEncode();
52
53 // decode
54 RibEntry decoded = new RibEntry();
55 decoded.wireDecode(encoded.buf());
56
57 // test
58 Assert.assertEquals(entry.getName().toUri(), decoded.getName().toUri());
59 Assert.assertEquals(entry.getRoutes().get(0).getFaceId(), decoded.getRoutes().get(0).getFaceId());
60 Assert.assertEquals(entry.getRoutes().get(0).getCost(), decoded.getRoutes().get(0).getCost());
61 Assert.assertEquals(entry.getRoutes().get(0).getOrigin(), decoded.getRoutes().get(0).getOrigin());
62 }
63
64 /**
65 * Integration test to run on actual system
66 *
67 * @param args
68 * @throws EncodingException
69 */
70 public static void main(String[] args) throws Exception {
71 Face forwarder = new Face("localhost");
72
73 // build management Interest packet; see http://redmine.named-data.net/projects/nfd/wiki/StatusDataset
74 Interest interest = new Interest(new Name("/localhost/nfd/rib/list"));
75 interest.setMustBeFresh(true);
76 interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
77 interest.setInterestLifetimeMilliseconds(2000.0);
78
79 // send packet
80 Data data = Client.getDefault().getSync(forwarder, interest);
81
82 // decode results
83 List<RibEntry> results = StatusDataset.wireDecode(data.getContent(), RibEntry.class);
84 assertTrue(results.size() > 0);
85 assertEquals("/localhost/nfd", results.get(0).getName().toUri());
86 }
87}