コード例 #1
0
  /**
   * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext,
   * OfHeader)} with empty port stats
   */
  @Test
  public void testEmptyPortStats() {
    MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder();
    mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    mpBuilder.setXid(123L);
    mpBuilder.setFlags(new MultipartRequestFlags(false));
    mpBuilder.setType(MultipartType.OFPMPPORTSTATS);

    MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder();
    MultipartReplyPortStatsBuilder statsBuilder = new MultipartReplyPortStatsBuilder();
    List<PortStats> portStats = new ArrayList<>();
    statsBuilder.setPortStats(portStats);
    caseBuilder.setMultipartReplyPortStats(statsBuilder.build());
    mpBuilder.setMultipartReplyBody(caseBuilder.build());
    MultipartReplyMessage message = mpBuilder.build();

    List<DataObject> list = translator.translate(cookie, sc, message);

    Assert.assertEquals("Wrong list size", 1, list.size());
    NodeConnectorStatisticsUpdate statUpdate = (NodeConnectorStatisticsUpdate) list.get(0);
    Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue());
    Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies());
    Assert.assertEquals(
        "Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue());
    Assert.assertEquals(
        "Wrong port stats size", 0, statUpdate.getNodeConnectorStatisticsAndPortNumberMap().size());
  }
コード例 #2
0
  /**
   * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext,
   * OfHeader)} with port stats
   */
  @Test
  public void testPortStats() {
    MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder();
    mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    mpBuilder.setXid(123L);
    mpBuilder.setFlags(new MultipartRequestFlags(false));
    mpBuilder.setType(MultipartType.OFPMPPORTSTATS);

    MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder();
    MultipartReplyPortStatsBuilder statsBuilder = new MultipartReplyPortStatsBuilder();
    List<PortStats> portStats = new ArrayList<>();
    PortStatsBuilder builder = new PortStatsBuilder();
    builder.setPortNo(1L);
    builder.setRxPackets(new BigInteger("2"));
    builder.setTxPackets(new BigInteger("3"));
    builder.setRxBytes(new BigInteger("4"));
    builder.setTxBytes(new BigInteger("5"));
    builder.setRxDropped(new BigInteger("6"));
    builder.setTxDropped(new BigInteger("7"));
    builder.setRxErrors(new BigInteger("8"));
    builder.setTxErrors(new BigInteger("9"));
    builder.setRxFrameErr(new BigInteger("10"));
    builder.setRxOverErr(new BigInteger("11"));
    builder.setRxCrcErr(new BigInteger("12"));
    builder.setCollisions(new BigInteger("13"));
    builder.setDurationSec(14L);
    builder.setDurationNsec(15L);
    portStats.add(builder.build());
    builder = new PortStatsBuilder();
    builder.setPortNo(BinContent.intToUnsignedLong(PortNumberValues.CONTROLLER.getIntValue()));
    builder.setRxPackets(new BigInteger("20"));
    builder.setTxPackets(new BigInteger("30"));
    builder.setRxBytes(new BigInteger("40"));
    builder.setTxBytes(new BigInteger("50"));
    builder.setRxDropped(new BigInteger("60"));
    builder.setTxDropped(new BigInteger("70"));
    builder.setRxErrors(new BigInteger("80"));
    builder.setTxErrors(new BigInteger("90"));
    builder.setRxFrameErr(new BigInteger("100"));
    builder.setRxOverErr(new BigInteger("110"));
    builder.setRxCrcErr(new BigInteger("120"));
    builder.setCollisions(new BigInteger("130"));
    portStats.add(builder.build());
    statsBuilder.setPortStats(portStats);
    caseBuilder.setMultipartReplyPortStats(statsBuilder.build());
    mpBuilder.setMultipartReplyBody(caseBuilder.build());
    MultipartReplyMessage message = mpBuilder.build();

    List<DataObject> list = translator.translate(cookie, sc, message);

    Assert.assertEquals("Wrong list size", 1, list.size());
    NodeConnectorStatisticsUpdate statUpdate = (NodeConnectorStatisticsUpdate) list.get(0);
    Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue());
    Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies());
    Assert.assertEquals(
        "Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue());
    Assert.assertEquals(
        "Wrong port stats size", 2, statUpdate.getNodeConnectorStatisticsAndPortNumberMap().size());
    NodeConnectorStatisticsAndPortNumberMap stat =
        statUpdate.getNodeConnectorStatisticsAndPortNumberMap().get(0);
    Assert.assertEquals("Wrong port number", "openflow:42:1", stat.getNodeConnectorId().getValue());
    Assert.assertEquals("Wrong rx packets", 2, stat.getPackets().getReceived().intValue());
    Assert.assertEquals("Wrong tx packets", 3, stat.getPackets().getTransmitted().intValue());
    Assert.assertEquals("Wrong rx bytes", 4, stat.getBytes().getReceived().intValue());
    Assert.assertEquals("Wrong tx bytes", 5, stat.getBytes().getTransmitted().intValue());
    Assert.assertEquals("Wrong rx dropped", 6, stat.getReceiveDrops().intValue());
    Assert.assertEquals("Wrong tx dropped", 7, stat.getTransmitDrops().intValue());
    Assert.assertEquals("Wrong rx errors", 8, stat.getReceiveErrors().intValue());
    Assert.assertEquals("Wrong tx errors", 9, stat.getTransmitErrors().intValue());
    Assert.assertEquals("Wrong rx frame error", 10, stat.getReceiveFrameError().intValue());
    Assert.assertEquals("Wrong rx over error", 11, stat.getReceiveOverRunError().intValue());
    Assert.assertEquals("Wrong rx crc error", 12, stat.getReceiveCrcError().intValue());
    Assert.assertEquals("Wrong collision count", 13, stat.getCollisionCount().intValue());
    Assert.assertEquals(
        "Wrong duration sec", 14, stat.getDuration().getSecond().getValue().intValue());
    Assert.assertEquals(
        "Wrong duration n sec", 15, stat.getDuration().getNanosecond().getValue().intValue());
    stat = statUpdate.getNodeConnectorStatisticsAndPortNumberMap().get(1);
    Assert.assertEquals(
        "Wrong port number", "openflow:42:CONTROLLER", stat.getNodeConnectorId().getValue());
    Assert.assertEquals("Wrong rx packets", 20, stat.getPackets().getReceived().intValue());
    Assert.assertEquals("Wrong tx packets", 30, stat.getPackets().getTransmitted().intValue());
    Assert.assertEquals("Wrong rx bytes", 40, stat.getBytes().getReceived().intValue());
    Assert.assertEquals("Wrong tx bytes", 50, stat.getBytes().getTransmitted().intValue());
    Assert.assertEquals("Wrong rx dropped", 60, stat.getReceiveDrops().intValue());
    Assert.assertEquals("Wrong tx dropped", 70, stat.getTransmitDrops().intValue());
    Assert.assertEquals("Wrong rx errors", 80, stat.getReceiveErrors().intValue());
    Assert.assertEquals("Wrong tx errors", 90, stat.getTransmitErrors().intValue());
    Assert.assertEquals("Wrong rx frame error", 100, stat.getReceiveFrameError().intValue());
    Assert.assertEquals("Wrong rx over error", 110, stat.getReceiveOverRunError().intValue());
    Assert.assertEquals("Wrong rx crc error", 120, stat.getReceiveCrcError().intValue());
    Assert.assertEquals("Wrong collision count", 130, stat.getCollisionCount().intValue());
    Assert.assertEquals("Wrong duration sec", null, stat.getDuration().getSecond());
    Assert.assertEquals("Wrong duration n sec", null, stat.getDuration().getNanosecond());
  }