/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with empty table stats */ @Test public void testEmptyTableStats() { MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); mpBuilder.setXid(123L); mpBuilder.setFlags(new MultipartRequestFlags(false)); mpBuilder.setType(MultipartType.OFPMPTABLE); MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder statsBuilder = new MultipartReplyTableBuilder(); List<TableStats> tableStats = new ArrayList<>(); statsBuilder.setTableStats(tableStats); caseBuilder.setMultipartReplyTable(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()); FlowTableStatisticsUpdate statUpdate = (FlowTableStatisticsUpdate) 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 table stats size", 0, statUpdate.getFlowTableAndStatisticsMap().size()); }
/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with table stats */ @Test public void testTableStats() { MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); mpBuilder.setXid(123L); mpBuilder.setFlags(new MultipartRequestFlags(false)); mpBuilder.setType(MultipartType.OFPMPTABLE); MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder(); MultipartReplyTableBuilder statsBuilder = new MultipartReplyTableBuilder(); List<TableStats> tableStats = new ArrayList<>(); TableStatsBuilder builder = new TableStatsBuilder(); builder.setTableId((short) 1); builder.setActiveCount(2L); builder.setLookupCount(new BigInteger("3")); builder.setMatchedCount(new BigInteger("4")); tableStats.add(builder.build()); builder = new TableStatsBuilder(); builder.setTableId((short) 10); builder.setActiveCount(20L); builder.setLookupCount(new BigInteger("30")); builder.setMatchedCount(new BigInteger("40")); tableStats.add(builder.build()); statsBuilder.setTableStats(tableStats); caseBuilder.setMultipartReplyTable(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()); FlowTableStatisticsUpdate statUpdate = (FlowTableStatisticsUpdate) 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 table stats size", 2, statUpdate.getFlowTableAndStatisticsMap().size()); FlowTableAndStatisticsMap stat = statUpdate.getFlowTableAndStatisticsMap().get(0); Assert.assertEquals("Wrong table-id", 1, stat.getTableId().getValue().intValue()); Assert.assertEquals("Wrong active count", 2, stat.getActiveFlows().getValue().intValue()); Assert.assertEquals("Wrong lookup count", 3, stat.getPacketsLookedUp().getValue().intValue()); Assert.assertEquals("Wrong matched count", 4, stat.getPacketsMatched().getValue().intValue()); stat = statUpdate.getFlowTableAndStatisticsMap().get(1); Assert.assertEquals("Wrong table-id", 10, stat.getTableId().getValue().intValue()); Assert.assertEquals("Wrong active count", 20, stat.getActiveFlows().getValue().intValue()); Assert.assertEquals("Wrong lookup count", 30, stat.getPacketsLookedUp().getValue().intValue()); Assert.assertEquals("Wrong matched count", 40, stat.getPacketsMatched().getValue().intValue()); }