blob: c7fe21e24ed0221c93f2c8d14003bdb686dfe605 [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.RibEntry;
18import com.intel.jndn.management.types.Route;
Andrew Brownbaf21d52015-07-13 10:32:46 -070019import com.intel.jndn.utils.client.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 encoding/decoding for RibEntry.
34 *
35 * @author Andrew Brown <andrew.brown@intel.com>
36 */
37public class RibEntryTest {
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 Route route = new Route();
47 route.setFaceId(42);
48 route.setCost(100);
49 route.setOrigin(0);
50 RibEntry entry = new RibEntry();
51 entry.setName(new Name("/rib/entry/test"));
52 entry.getRoutes().add(route);
Andrew Brownc46c1602015-02-18 10:45:56 -080053
Andrew Brown211d2b62015-02-18 11:12:02 -080054 // encode
55 Blob encoded = entry.wireEncode();
Andrew Brownc46c1602015-02-18 10:45:56 -080056
Andrew Brown211d2b62015-02-18 11:12:02 -080057 // decode
58 RibEntry decoded = new RibEntry();
59 decoded.wireDecode(encoded.buf());
Andrew Brownc46c1602015-02-18 10:45:56 -080060
Andrew Brown211d2b62015-02-18 11:12:02 -080061 // test
62 Assert.assertEquals(entry.getName().toUri(), decoded.getName().toUri());
63 Assert.assertEquals(entry.getRoutes().get(0).getFaceId(), decoded.getRoutes().get(0).getFaceId());
64 Assert.assertEquals(entry.getRoutes().get(0).getCost(), decoded.getRoutes().get(0).getCost());
65 Assert.assertEquals(entry.getRoutes().get(0).getOrigin(), decoded.getRoutes().get(0).getOrigin());
66 }
Andrew Brownc46c1602015-02-18 10:45:56 -080067
Andrew Brown211d2b62015-02-18 11:12:02 -080068 /**
69 * Integration test to run on actual system
70 *
71 * @param args
72 * @throws EncodingException
73 */
74 public static void main(String[] args) throws Exception {
75 Face forwarder = new Face("localhost");
Andrew Brownc46c1602015-02-18 10:45:56 -080076
andrewsbrown9a6d7ba2015-03-24 09:53:29 -070077 // build management Interest packet; see <a href="http://redmine.named-data.net/projects/nfd/wiki/StatusDataset">http://redmine.named-data.net/projects/nfd/wiki/StatusDataset</a>
Andrew Brown211d2b62015-02-18 11:12:02 -080078 Interest interest = new Interest(new Name("/localhost/nfd/rib/list"));
79 interest.setMustBeFresh(true);
80 interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT);
81 interest.setInterestLifetimeMilliseconds(2000.0);
Andrew Brownc46c1602015-02-18 10:45:56 -080082
Andrew Brown211d2b62015-02-18 11:12:02 -080083 // send packet
andrewsbrown43b96302015-03-17 21:51:43 +010084 Data data = SimpleClient.getDefault().getSync(forwarder, interest);
Andrew Brownc46c1602015-02-18 10:45:56 -080085
Andrew Brown211d2b62015-02-18 11:12:02 -080086 // decode results
87 List<RibEntry> results = StatusDataset.wireDecode(data.getContent(), RibEntry.class);
88 assertTrue(results.size() > 0);
andrewsbrown6251c372015-03-09 14:52:04 -070089 assertEquals("/localhost/nfd/rib", results.get(0).getName().toUri());
Andrew Brown211d2b62015-02-18 11:12:02 -080090 }
Andrew Brownc46c1602015-02-18 10:45:56 -080091}