/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with empty flow stats */ @Test public void testEmptyFlowCase() { MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); mpBuilder.setXid(123L); mpBuilder.setFlags(new MultipartRequestFlags(false)); mpBuilder.setType(MultipartType.OFPMPFLOW); MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder(); MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); List<FlowStats> flowStats = new ArrayList<>(); flowBuilder.setFlowStats(flowStats); caseBuilder.setMultipartReplyFlow(flowBuilder.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()); FlowsStatisticsUpdate flowUpdate = (FlowsStatisticsUpdate) list.get(0); Assert.assertEquals("Wrong node-id", "openflow:42", flowUpdate.getId().getValue()); Assert.assertEquals("Wrong more-replies", false, flowUpdate.isMoreReplies()); Assert.assertEquals( "Wrong transaction-id", 123, flowUpdate.getTransactionId().getValue().intValue()); List<FlowAndStatisticsMapList> mapList = flowUpdate.getFlowAndStatisticsMapList(); Assert.assertEquals("Wrong flow stats size", 0, mapList.size()); }
/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with experimenter MultipartReply message */ @Test public void testFlowCase() { MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); mpBuilder.setXid(123L); mpBuilder.setFlags(new MultipartRequestFlags(false)); mpBuilder.setType(MultipartType.OFPMPFLOW); MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder(); MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); List<FlowStats> flowStats = new ArrayList<>(); FlowStatsBuilder statsBuilder = new FlowStatsBuilder(); statsBuilder.setTableId((short) 1); statsBuilder.setDurationSec(2L); statsBuilder.setDurationNsec(3L); statsBuilder.setPriority(4); statsBuilder.setIdleTimeout(5); statsBuilder.setHardTimeout(6); FlowModFlags flags = new FlowModFlags(true, false, true, false, true); statsBuilder.setFlags(flags); statsBuilder.setCookie(new BigInteger("7")); statsBuilder.setPacketCount(new BigInteger("8")); statsBuilder.setByteCount(new BigInteger("9")); MatchBuilder matchBuilder = new MatchBuilder(); matchBuilder.setType(OxmMatchType.class); matchBuilder.setMatchEntry(new ArrayList<MatchEntry>()); statsBuilder.setMatch(matchBuilder.build()); statsBuilder.setInstruction(new ArrayList<Instruction>()); flowStats.add(statsBuilder.build()); statsBuilder = new FlowStatsBuilder(); statsBuilder.setTableId((short) 10); statsBuilder.setDurationSec(20L); statsBuilder.setDurationNsec(30L); statsBuilder.setPriority(40); statsBuilder.setIdleTimeout(50); statsBuilder.setHardTimeout(60); flags = new FlowModFlags(false, true, false, true, false); statsBuilder.setFlags(flags); statsBuilder.setCookie(new BigInteger("70")); statsBuilder.setPacketCount(new BigInteger("80")); statsBuilder.setByteCount(new BigInteger("90")); matchBuilder = new MatchBuilder(); matchBuilder.setType(OxmMatchType.class); matchBuilder.setMatchEntry(new ArrayList<MatchEntry>()); statsBuilder.setMatch(matchBuilder.build()); statsBuilder.setInstruction(new ArrayList<Instruction>()); flowStats.add(statsBuilder.build()); flowBuilder.setFlowStats(flowStats); caseBuilder.setMultipartReplyFlow(flowBuilder.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()); FlowsStatisticsUpdate flowUpdate = (FlowsStatisticsUpdate) list.get(0); Assert.assertEquals("Wrong node-id", "openflow:42", flowUpdate.getId().getValue()); Assert.assertEquals("Wrong more-replies", false, flowUpdate.isMoreReplies()); Assert.assertEquals( "Wrong transaction-id", 123, flowUpdate.getTransactionId().getValue().intValue()); List<FlowAndStatisticsMapList> mapList = flowUpdate.getFlowAndStatisticsMapList(); Assert.assertEquals("Wrong flow stats size", 2, mapList.size()); FlowAndStatisticsMapList stat = mapList.get(0); Assert.assertEquals("Wrong table-id", 1, stat.getTableId().intValue()); Assert.assertEquals( "Wrong duration sec", 2, stat.getDuration().getSecond().getValue().intValue()); Assert.assertEquals( "Wrong duration n sec", 3, stat.getDuration().getNanosecond().getValue().intValue()); Assert.assertEquals("Wrong priority", 4, stat.getPriority().intValue()); Assert.assertEquals("Wrong idle-timeout", 5, stat.getIdleTimeout().intValue()); Assert.assertEquals("Wrong hard-timeout", 6, stat.getHardTimeout().intValue()); org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags expectedFlags = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags( !flags.isOFPFFCHECKOVERLAP(), !flags.isOFPFFNOBYTCOUNTS(), !flags.isOFPFFNOPKTCOUNTS(), !flags.isOFPFFRESETCOUNTS(), !flags.isOFPFFSENDFLOWREM()); Assert.assertEquals("Wrong flags", expectedFlags, stat.getFlags()); Assert.assertEquals("Wrong cookie", 7, stat.getCookie().getValue().intValue()); Assert.assertEquals("Wrong packet count", 8, stat.getPacketCount().getValue().intValue()); Assert.assertEquals("Wrong byte count", 9, stat.getByteCount().getValue().intValue()); org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder emptyMatchBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow .MatchBuilder(); Match emptyMatch = emptyMatchBuilder.build(); Assert.assertEquals("Wrong match", emptyMatch, stat.getMatch()); Assert.assertEquals("Wrong instructions", 0, stat.getInstructions().getInstruction().size()); stat = mapList.get(1); Assert.assertEquals("Wrong table-id", 10, stat.getTableId().intValue()); Assert.assertEquals( "Wrong duration sec", 20, stat.getDuration().getSecond().getValue().intValue()); Assert.assertEquals( "Wrong duration n sec", 30, stat.getDuration().getNanosecond().getValue().intValue()); Assert.assertEquals("Wrong priority", 40, stat.getPriority().intValue()); Assert.assertEquals("Wrong idle-timeout", 50, stat.getIdleTimeout().intValue()); Assert.assertEquals("Wrong hard-timeout", 60, stat.getHardTimeout().intValue()); expectedFlags = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags( flags.isOFPFFCHECKOVERLAP(), flags.isOFPFFNOBYTCOUNTS(), flags.isOFPFFNOPKTCOUNTS(), flags.isOFPFFRESETCOUNTS(), flags.isOFPFFSENDFLOWREM()); Assert.assertEquals("Wrong flags", expectedFlags, stat.getFlags()); Assert.assertEquals("Wrong cookie", 70, stat.getCookie().getValue().intValue()); Assert.assertEquals("Wrong packet count", 80, stat.getPacketCount().getValue().intValue()); Assert.assertEquals("Wrong byte count", 90, stat.getByteCount().getValue().intValue()); Assert.assertEquals("Wrong match", emptyMatch, stat.getMatch()); Assert.assertEquals("Wrong instructions", 0, stat.getInstructions().getInstruction().size()); }