@Test
  public void testGetFlows() {
    try {
      Node node = new Node("STUB", new Integer(0xCAFE));
      List<FlowOnNode> flows = this.manager.getFlows(node);
      FlowOnNode fn = flows.get(0);
      Assert.assertTrue(fn.getByteCount() == 100);
      Assert.assertTrue(fn.getDurationNanoseconds() == 400);
      Assert.assertTrue(fn.getDurationSeconds() == 40);
      Assert.assertTrue(fn.getTableId() == (byte) 0x1);
      Assert.assertTrue(fn.getPacketCount() == 200);

      Match match = new Match();
      try {
        match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
      } catch (UnknownHostException e) {
        fail("Couldn't create match");
      }
      Assert.assertTrue(match.equals(fn.getFlow().getMatch()));
      Assert.assertTrue(fn.getFlow().getActions().get(0).equals(new Drop()));
    } catch (ConstructionException e) {
      // Got an unexpected exception
      Assert.assertTrue(false);
    }
  }
コード例 #2
0
  @Test
  public void testGetFlowStatistics() {
    Flow flow = new Flow();

    Match match = new Match();
    try {
      match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
    } catch (UnknownHostException e) {
    }
    flow.setMatch(match);
    Action action = new Drop();

    List<Action> actions = new ArrayList<Action>();
    actions.add(action);
    flow.setActions(actions);
    // as in stub
    flow.setPriority((short) 3500);
    flow.setIdleTimeout((short) 1000);
    flow.setHardTimeout((short) 2000);
    flow.setId(12345);

    try {
      Node node = new Node("STUB", 0xCAFE);
      FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
      List<FlowEntry> list = new ArrayList<FlowEntry>();
      list.add(fe);
      FlowEntry fe2 = new FlowEntry("g1", "f2", flow, node);
      list.add(fe2);

      Map<Node, List<FlowOnNode>> result = this.manager.getFlowStatisticsForFlowList(null);
      Assert.assertTrue(result.isEmpty());
      result = this.manager.getFlowStatisticsForFlowList(list);
      List<FlowOnNode> results = result.get(node);
      FlowOnNode fn = results.get(0);
      Assert.assertTrue(fn.getByteCount() == 100);
      Assert.assertTrue(fn.getDurationNanoseconds() == 400);
      Assert.assertTrue(fn.getDurationSeconds() == 40);
      Assert.assertTrue(fn.getTableId() == (byte) 0x1);
      Assert.assertTrue(fn.getPacketCount() == 200);
      Assert.assertTrue(fn.getFlow().equals(flow));
    } catch (ConstructionException e) {
      Assert.assertTrue(false);
    }
  }