/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with null and incorrect message */ @Test public void test() { List<DataObject> list = translator.translate(cookie, sc, null); Assert.assertEquals("Wrong list size", 0, list.size()); HelloMessageBuilder helloBuilder = new HelloMessageBuilder(); list = translator.translate(cookie, sc, helloBuilder.build()); Assert.assertEquals("Wrong list size", 0, list.size()); }
/** * 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 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()); }
/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with experimenter MultipartReply message */ @Test public void testExperimenterCase() { MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); mpBuilder.setXid(123L); mpBuilder.setFlags(new MultipartRequestFlags(false)); mpBuilder.setType(MultipartType.OFPMPEXPERIMENTER); MultipartReplyMessage message = mpBuilder.build(); List<DataObject> list = translator.translate(cookie, sc, message); Assert.assertEquals("Wrong list size", 0, list.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()); }
/** * 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()); }
/** * Test {@link MultipartReplyTranslator#translate(SwitchConnectionDistinguisher, SessionContext, * OfHeader)} with queue stats */ @Test public void testQueueStats() { MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); mpBuilder.setXid(123L); mpBuilder.setFlags(new MultipartRequestFlags(false)); mpBuilder.setType(MultipartType.OFPMPQUEUE); MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder(); MultipartReplyQueueBuilder statsBuilder = new MultipartReplyQueueBuilder(); List<QueueStats> queueStats = new ArrayList<>(); QueueStatsBuilder builder = new QueueStatsBuilder(); builder.setPortNo(BinContent.intToUnsignedLong(PortNumberValues.FLOOD.getIntValue())); builder.setQueueId(2L); builder.setTxPackets(new BigInteger("3")); builder.setTxBytes(new BigInteger("4")); builder.setTxErrors(new BigInteger("5")); builder.setDurationSec(6L); builder.setDurationNsec(7L); queueStats.add(builder.build()); builder = new QueueStatsBuilder(); builder.setPortNo(BinContent.intToUnsignedLong(PortNumberValues.INPORT.getIntValue())); builder.setQueueId(20L); builder.setTxPackets(new BigInteger("30")); builder.setTxBytes(new BigInteger("40")); builder.setTxErrors(new BigInteger("50")); builder.setDurationSec(60L); builder.setDurationNsec(70L); queueStats.add(builder.build()); statsBuilder.setQueueStats(queueStats); caseBuilder.setMultipartReplyQueue(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()); QueueStatisticsUpdate statUpdate = (QueueStatisticsUpdate) 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 queue stats size", 2, statUpdate.getQueueIdAndStatisticsMap().size()); QueueIdAndStatisticsMap stat = statUpdate.getQueueIdAndStatisticsMap().get(0); Assert.assertEquals( "Wrong port number", "openflow:42:FLOOD", stat.getNodeConnectorId().getValue()); Assert.assertEquals("Wrong queue-id", 2, stat.getQueueId().getValue().intValue()); Assert.assertEquals("Wrong tx packets", 3, stat.getTransmittedPackets().getValue().intValue()); Assert.assertEquals("Wrong tx bytes", 4, stat.getTransmittedBytes().getValue().intValue()); Assert.assertEquals("Wrong tx errors", 5, stat.getTransmissionErrors().getValue().intValue()); Assert.assertEquals( "Wrong duration sec", 6, stat.getDuration().getSecond().getValue().intValue()); Assert.assertEquals( "Wrong duration n sec", 7, stat.getDuration().getNanosecond().getValue().intValue()); stat = statUpdate.getQueueIdAndStatisticsMap().get(1); Assert.assertEquals( "Wrong port number", "openflow:42:INPORT", stat.getNodeConnectorId().getValue()); Assert.assertEquals("Wrong queue-id", 20, stat.getQueueId().getValue().intValue()); Assert.assertEquals("Wrong tx packets", 30, stat.getTransmittedPackets().getValue().intValue()); Assert.assertEquals("Wrong tx bytes", 40, stat.getTransmittedBytes().getValue().intValue()); Assert.assertEquals("Wrong tx errors", 50, stat.getTransmissionErrors().getValue().intValue()); Assert.assertEquals( "Wrong duration sec", 60, stat.getDuration().getSecond().getValue().intValue()); Assert.assertEquals( "Wrong duration n sec", 70, stat.getDuration().getNanosecond().getValue().intValue()); }
/** * 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()); }
@Override public List<DataObject> translate( final SwitchConnectionDistinguisher cookie, final SessionContext sc, final OfHeader msg) { List<DataObject> listDataObject = new CopyOnWriteArrayList<DataObject>(); OpenflowVersion ofVersion = OpenflowVersion.get(sc.getPrimaryConductor().getVersion()); if (msg instanceof MultipartReplyMessage) { MultipartReplyMessage mpReply = (MultipartReplyMessage) msg; NodeId node = MultipartReplyTranslator.nodeIdFromDatapathId(sc.getFeatures().getDatapathId()); switch (mpReply.getType()) { case OFPMPFLOW: { logger.debug( "Received flow statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+"); FlowsStatisticsUpdateBuilder message = new FlowsStatisticsUpdateBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody(); MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow(); message.setFlowAndStatisticsMapList( flowStatsConvertor.toSALFlowStatsList( replyBody.getFlowStats(), sc.getFeatures().getDatapathId(), ofVersion)); logger.debug("Converted flow statistics : {}", message.build().toString()); listDataObject.add(message.build()); return listDataObject; } case OFPMPAGGREGATE: { logger.debug( "Received aggregate flow statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+"); AggregateFlowStatisticsUpdateBuilder message = new AggregateFlowStatisticsUpdateBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyAggregateCase caseBody = (MultipartReplyAggregateCase) mpReply.getMultipartReplyBody(); MultipartReplyAggregate replyBody = caseBody.getMultipartReplyAggregate(); message.setByteCount(new Counter64(replyBody.getByteCount())); message.setPacketCount(new Counter64(replyBody.getPacketCount())); message.setFlowCount(new Counter32(replyBody.getFlowCount())); logger.debug("Converted aggregate flow statistics : {}", message.build().toString()); listDataObject.add(message.build()); return listDataObject; } case OFPMPPORTSTATS: { logger.debug("Received port statistics multipart response"); NodeConnectorStatisticsUpdateBuilder message = new NodeConnectorStatisticsUpdateBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyPortStatsCase caseBody = (MultipartReplyPortStatsCase) mpReply.getMultipartReplyBody(); MultipartReplyPortStats replyBody = caseBody.getMultipartReplyPortStats(); List<NodeConnectorStatisticsAndPortNumberMap> statsMap = new ArrayList<NodeConnectorStatisticsAndPortNumberMap>(); for (PortStats portStats : replyBody.getPortStats()) { NodeConnectorStatisticsAndPortNumberMapBuilder statsBuilder = new NodeConnectorStatisticsAndPortNumberMapBuilder(); statsBuilder.setNodeConnectorId( InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo( sc.getFeatures().getDatapathId(), portStats.getPortNo(), ofVersion)); BytesBuilder bytesBuilder = new BytesBuilder(); bytesBuilder.setReceived(portStats.getRxBytes()); bytesBuilder.setTransmitted(portStats.getTxBytes()); statsBuilder.setBytes(bytesBuilder.build()); PacketsBuilder packetsBuilder = new PacketsBuilder(); packetsBuilder.setReceived(portStats.getRxPackets()); packetsBuilder.setTransmitted(portStats.getTxPackets()); statsBuilder.setPackets(packetsBuilder.build()); DurationBuilder durationBuilder = new DurationBuilder(); if (portStats.getDurationSec() != null) { durationBuilder.setSecond(new Counter32(portStats.getDurationSec())); } if (portStats.getDurationNsec() != null) { durationBuilder.setNanosecond(new Counter32(portStats.getDurationNsec())); } statsBuilder.setDuration(durationBuilder.build()); statsBuilder.setCollisionCount(portStats.getCollisions()); statsBuilder.setKey( new NodeConnectorStatisticsAndPortNumberMapKey( statsBuilder.getNodeConnectorId())); statsBuilder.setReceiveCrcError(portStats.getRxCrcErr()); statsBuilder.setReceiveDrops(portStats.getRxDropped()); statsBuilder.setReceiveErrors(portStats.getRxErrors()); statsBuilder.setReceiveFrameError(portStats.getRxFrameErr()); statsBuilder.setReceiveOverRunError(portStats.getRxOverErr()); statsBuilder.setTransmitDrops(portStats.getTxDropped()); statsBuilder.setTransmitErrors(portStats.getTxErrors()); statsMap.add(statsBuilder.build()); } message.setNodeConnectorStatisticsAndPortNumberMap(statsMap); logger.debug("Converted ports statistics : {}", message.build().toString()); listDataObject.add(message.build()); return listDataObject; } case OFPMPGROUP: { logger.debug("Received group statistics multipart reponse"); GroupStatisticsUpdatedBuilder message = new GroupStatisticsUpdatedBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyGroupCase caseBody = (MultipartReplyGroupCase) mpReply.getMultipartReplyBody(); MultipartReplyGroup replyBody = caseBody.getMultipartReplyGroup(); message.setGroupStats( groupStatsConvertor.toSALGroupStatsList(replyBody.getGroupStats())); logger.debug("Converted group statistics : {}", message.toString()); listDataObject.add(message.build()); return listDataObject; } case OFPMPGROUPDESC: { logger.debug("Received group description statistics multipart reponse"); GroupDescStatsUpdatedBuilder message = new GroupDescStatsUpdatedBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyGroupDescCase caseBody = (MultipartReplyGroupDescCase) mpReply.getMultipartReplyBody(); MultipartReplyGroupDesc replyBody = caseBody.getMultipartReplyGroupDesc(); message.setGroupDescStats( groupStatsConvertor.toSALGroupDescStatsList(replyBody.getGroupDesc(), ofVersion)); logger.debug("Converted group statistics : {}", message.toString()); listDataObject.add(message.build()); return listDataObject; } case OFPMPGROUPFEATURES: { logger.debug("Received group features multipart reponse"); GroupFeaturesUpdatedBuilder message = new GroupFeaturesUpdatedBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyGroupFeaturesCase caseBody = (MultipartReplyGroupFeaturesCase) mpReply.getMultipartReplyBody(); MultipartReplyGroupFeatures replyBody = caseBody.getMultipartReplyGroupFeatures(); List<Class<? extends GroupType>> supportedGroups = new ArrayList<Class<? extends GroupType>>(); if (replyBody.getTypes().isOFPGTALL()) { supportedGroups.add(GroupAll.class); } if (replyBody.getTypes().isOFPGTSELECT()) { supportedGroups.add(GroupSelect.class); } if (replyBody.getTypes().isOFPGTINDIRECT()) { supportedGroups.add(GroupIndirect.class); } if (replyBody.getTypes().isOFPGTFF()) { supportedGroups.add(GroupFf.class); } message.setGroupTypesSupported(supportedGroups); message.setMaxGroups(replyBody.getMaxGroups()); List<Class<? extends GroupCapability>> supportedCapabilities = new ArrayList<Class<? extends GroupCapability>>(); if (replyBody.getCapabilities().isOFPGFCCHAINING()) { supportedCapabilities.add(Chaining.class); } if (replyBody.getCapabilities().isOFPGFCCHAININGCHECKS()) { supportedCapabilities.add(ChainingChecks.class); } if (replyBody.getCapabilities().isOFPGFCSELECTLIVENESS()) { supportedCapabilities.add(SelectLiveness.class); } if (replyBody.getCapabilities().isOFPGFCSELECTWEIGHT()) { supportedCapabilities.add(SelectWeight.class); } message.setGroupCapabilitiesSupported(supportedCapabilities); message.setActions(getGroupActionsSupportBitmap(replyBody.getActionsBitmap())); listDataObject.add(message.build()); return listDataObject; } case OFPMPMETER: { logger.debug("Received meter statistics multipart reponse"); MeterStatisticsUpdatedBuilder message = new MeterStatisticsUpdatedBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody(); MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter(); message.setMeterStats( meterStatsConvertor.toSALMeterStatsList(replyBody.getMeterStats())); listDataObject.add(message.build()); return listDataObject; } case OFPMPMETERCONFIG: { logger.debug("Received meter config statistics multipart reponse"); MeterConfigStatsUpdatedBuilder message = new MeterConfigStatsUpdatedBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyMeterConfigCase caseBody = (MultipartReplyMeterConfigCase) mpReply.getMultipartReplyBody(); MultipartReplyMeterConfig replyBody = caseBody.getMultipartReplyMeterConfig(); message.setMeterConfigStats( meterStatsConvertor.toSALMeterConfigList(replyBody.getMeterConfig())); listDataObject.add(message.build()); return listDataObject; } case OFPMPMETERFEATURES: { logger.debug("Received meter features multipart reponse"); // Convert OF message and send it to SAL listener MeterFeaturesUpdatedBuilder message = new MeterFeaturesUpdatedBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyMeterFeaturesCase caseBody = (MultipartReplyMeterFeaturesCase) mpReply.getMultipartReplyBody(); MultipartReplyMeterFeatures replyBody = caseBody.getMultipartReplyMeterFeatures(); message.setMaxBands(replyBody.getMaxBands()); message.setMaxColor(replyBody.getMaxColor()); message.setMaxMeter(new Counter32(replyBody.getMaxMeter())); List<Class<? extends MeterCapability>> supportedCapabilities = new ArrayList<Class<? extends MeterCapability>>(); if (replyBody.getCapabilities().isOFPMFBURST()) { supportedCapabilities.add(MeterBurst.class); } if (replyBody.getCapabilities().isOFPMFKBPS()) { supportedCapabilities.add(MeterKbps.class); } if (replyBody.getCapabilities().isOFPMFPKTPS()) { supportedCapabilities.add(MeterPktps.class); } if (replyBody.getCapabilities().isOFPMFSTATS()) { supportedCapabilities.add(MeterStats.class); } message.setMeterCapabilitiesSupported(supportedCapabilities); List<Class<? extends MeterBand>> supportedMeterBand = new ArrayList<Class<? extends MeterBand>>(); if (replyBody.getBandTypes().isOFPMBTDROP()) { supportedMeterBand.add(MeterBandDrop.class); } if (replyBody.getBandTypes().isOFPMBTDSCPREMARK()) { supportedMeterBand.add(MeterBandDscpRemark.class); } message.setMeterBandSupported(supportedMeterBand); listDataObject.add(message.build()); return listDataObject; } case OFPMPTABLE: { logger.debug( "Received flow table statistics reponse from openflow {} switch", msg.getVersion() == 1 ? "1.0" : "1.3+"); FlowTableStatisticsUpdateBuilder message = new FlowTableStatisticsUpdateBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyTableCase caseBody = (MultipartReplyTableCase) mpReply.getMultipartReplyBody(); MultipartReplyTable replyBody = caseBody.getMultipartReplyTable(); List<TableStats> swTablesStats = replyBody.getTableStats(); List<FlowTableAndStatisticsMap> salFlowStats = new ArrayList<FlowTableAndStatisticsMap>(); for (TableStats swTableStats : swTablesStats) { FlowTableAndStatisticsMapBuilder statisticsBuilder = new FlowTableAndStatisticsMapBuilder(); statisticsBuilder.setActiveFlows(new Counter32(swTableStats.getActiveCount())); statisticsBuilder.setPacketsLookedUp(new Counter64(swTableStats.getLookupCount())); statisticsBuilder.setPacketsMatched(new Counter64(swTableStats.getMatchedCount())); statisticsBuilder.setTableId(new TableId(swTableStats.getTableId())); salFlowStats.add(statisticsBuilder.build()); } message.setFlowTableAndStatisticsMap(salFlowStats); logger.debug("Converted flow table statistics : {}", message.build().toString()); listDataObject.add(message.build()); return listDataObject; } case OFPMPQUEUE: { logger.debug("Received queue statistics multipart response"); QueueStatisticsUpdateBuilder message = new QueueStatisticsUpdateBuilder(); message.setId(node); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(generateTransactionId(mpReply.getXid())); MultipartReplyQueueCase caseBody = (MultipartReplyQueueCase) mpReply.getMultipartReplyBody(); MultipartReplyQueue replyBody = caseBody.getMultipartReplyQueue(); List<QueueIdAndStatisticsMap> statsMap = new ArrayList<QueueIdAndStatisticsMap>(); for (QueueStats queueStats : replyBody.getQueueStats()) { QueueIdAndStatisticsMapBuilder statsBuilder = new QueueIdAndStatisticsMapBuilder(); statsBuilder.setNodeConnectorId( InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo( sc.getFeatures().getDatapathId(), queueStats.getPortNo(), ofVersion)); statsBuilder.setTransmissionErrors(new Counter64(queueStats.getTxErrors())); statsBuilder.setTransmittedBytes(new Counter64(queueStats.getTxBytes())); statsBuilder.setTransmittedPackets(new Counter64(queueStats.getTxPackets())); DurationBuilder durationBuilder = new DurationBuilder(); durationBuilder.setSecond(new Counter32(queueStats.getDurationSec())); durationBuilder.setNanosecond(new Counter32(queueStats.getDurationNsec())); statsBuilder.setDuration(durationBuilder.build()); statsBuilder.setQueueId(new QueueId(queueStats.getQueueId())); statsBuilder.setNodeConnectorId( InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo( sc.getFeatures().getDatapathId(), queueStats.getPortNo(), ofVersion)); statsMap.add(statsBuilder.build()); } message.setQueueIdAndStatisticsMap(statsMap); logger.debug("Converted queue statistics : {}", message.build().toString()); listDataObject.add(message.build()); return listDataObject; } default: return listDataObject; } } return listDataObject; }