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