blob: da341a2605c0afc5c3ebf4fd592511da481073d0 [file] [log] [blame]
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -08001/*
2 * 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.
13 */
14package com.intel.jndn.management;
15
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -080016import com.intel.jndn.management.enums.LocalControlHeader;
17import com.intel.jndn.management.enums.Strategies;
18import com.intel.jndn.management.types.RibEntry;
19import com.intel.jndn.management.types.StrategyChoice;
20import com.intel.jndn.mock.MockKeyChain;
21import net.named_data.jndn.Face;
22import net.named_data.jndn.KeyLocator;
23import net.named_data.jndn.Name;
24import net.named_data.jndn.encoding.EncodingException;
25import net.named_data.jndn.security.KeyChain;
26import net.named_data.jndn.security.SecurityException;
27import org.junit.Before;
28import org.junit.Test;
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -080029
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080030import java.io.IOException;
31import java.util.List;
32import java.util.Random;
33import java.util.logging.Logger;
34
35import static org.junit.Assert.assertEquals;
36import static org.junit.Assert.assertFalse;
37import static org.junit.Assert.assertNotNull;
38import static org.junit.Assert.assertTrue;
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -080039
40/**
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -080041 * Testing Nfdc with real NFD instance (NFD must be run locally while executing the test).
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -080042 *
43 * @author Andrew Brown <andrew.brown@intel.com>
44 */
45public class NfdcIT {
46 private static final Logger LOG = Logger.getLogger(NfdcIT.class.getName());
47 private Face face;
48
49 @Before
50 public void setUp() throws SecurityException {
51 face = new Face("localhost");
52 KeyChain keyChain = MockKeyChain.configure(new Name("/tmp/identity"));
53 face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName());
54 }
55
56 @Test
57 public void testConnectivity() throws IOException, ManagementException {
58 KeyLocator keyLocator = Nfdc.getKeyLocator(face);
59 assertNotNull(keyLocator);
60 LOG.info("Connected to NFD with key locator: " + keyLocator.getKeyName().toUri());
61 }
62
63 @Test
64 public void testStatusDatasets() throws Exception {
65 assertTrue(Nfdc.getForwarderStatus(face).getStartTimestamp() > 0);
66 assertFalse(Nfdc.getFaceList(face).isEmpty());
67 assertFalse(Nfdc.getFibList(face).isEmpty());
68 assertFalse(Nfdc.getRouteList(face).isEmpty());
69 }
70
71 @Test
72 public void testRoutes() throws EncodingException, IOException, ManagementException, InterruptedException {
73 Nfdc.register(face, new Name("/my/route/to/app/face"), 333);
74 int faceId = Nfdc.createFace(face, "udp4://127.0.0.1:56363");
75 Nfdc.register(face, "udp4://127.0.0.1:56363", new Name("/my/test/route"), 999);
76 Nfdc.register(face, faceId, new Name("/"), 555);
77
78 // check that route is created
79 Thread.sleep(1000); // NFD registers the route asynchronously
80
81 boolean found = false;
82 for (RibEntry route : Nfdc.getRouteList(face)) {
83 LOG.info("Found route: " + route.getName().toUri());
84 if (route.getName().equals(new Name("/my/test/route"))) {
85 found = true;
86 }
87 }
88 assertTrue(found);
89
90 Nfdc.unregister(face, new Name("/my/route/to/app/face"));
91
92 // remove the route
93 Nfdc.unregister(face, new Name("/my/test/route"), "udp4://127.0.0.1:56363");
94
95 // remove face
96 Nfdc.destroyFace(face, faceId);
97 }
98
99 @Test
100 public void testStrategies() throws Exception {
101 Name prefix = new Name("/test/strategy").append("random:" + new Random().nextInt());
102
103 List<StrategyChoice> choices = Nfdc.getStrategyList(face);
104 int oldSize = choices.size();
105
106 Nfdc.setStrategy(face, prefix, Strategies.CLIENT_CONTROL);
107 Thread.sleep(1000); // strategy takes a while to register
108
109 choices = Nfdc.getStrategyList(face);
110 assertEquals(oldSize + 1, choices.size());
111
112 Nfdc.unsetStrategy(face, prefix);
113 }
114
115 /**
Alexander Afanasyeve36e1af2016-02-19 18:06:05 -0800116 * LocalControlHeader works only with NFD < 0.3.4, broken otherwise.
Alexander Afanasyeva8bc0d82016-01-25 17:25:30 -0800117 */
118 @Test(expected = ManagementException.class)
119 public void testLocalControlHeader() throws Exception {
120 Nfdc.enableLocalControlHeader(face, LocalControlHeader.INCOMING_FACE_ID);
121 Thread.sleep(1000); // strategy takes a while to register
122
123 // TODO: add asserts
124
125 Nfdc.disableLocalControlHeader(face, LocalControlHeader.INCOMING_FACE_ID);
126 }
127}