Search in sources :

Example 1 with OFPortStatsEntry

use of org.projectfloodlight.openflow.protocol.OFPortStatsEntry in project open-kilda by telstra.

the class OfPortStatsMapperTest method testToPortStatsDataV13.

@Test
public void testToPortStatsDataV13() {
    OFFactoryVer13 ofFactoryVer13 = new OFFactoryVer13();
    OFPortStatsEntry ofPortStatsEntry = prebuildPortStatsEntry(ofFactoryVer13.buildPortStatsEntry()).setRxFrameErr(U64.of(rxFrameErr)).setRxOverErr(U64.of(rxOverErr)).setRxCrcErr(U64.of(rxCrcErr)).setCollisions(U64.of(collisions)).build();
    OFPortStatsReply ofPortStatsReply = ofFactoryVer13.buildPortStatsReply().setXid(xId).setEntries(Collections.singletonList(ofPortStatsEntry)).build();
    PortStatsData data = OfPortStatsMapper.INSTANCE.toPostStatsData(Collections.singletonList(ofPortStatsReply), switchId);
    assertPortStatsData(data);
}
Also used : OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFPortStatsReply(org.projectfloodlight.openflow.protocol.OFPortStatsReply) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) Test(org.junit.Test)

Example 2 with OFPortStatsEntry

use of org.projectfloodlight.openflow.protocol.OFPortStatsEntry in project open-kilda by telstra.

the class OfPortStatsMapper method toPortStatsEntry.

/**
 * Convert {@link OFPortStatsEntry} to {@link PortStatsEntry}.
 * @param entry port stats entry to be converted.
 * @return result of transformation {@link PortStatsEntry} or null if object couldn't be parsed.
 */
public PortStatsEntry toPortStatsEntry(OFPortStatsEntry entry) {
    long rxFrameErr = 0L;
    long rxOverErr = 0L;
    long rxCrcErr = 0L;
    long collisions = 0L;
    try {
        // Since version OF_14 bellow described get***() methods throw UnsupportedOperationException
        if (entry.getVersion().compareTo(OFVersion.OF_13) > 0) {
            for (OFPortStatsProp property : entry.getProperties()) {
                if (property.getType() == ETHERNET_PROPERTY_TYPE) {
                    OFPortStatsPropEthernet etherProps = (OFPortStatsPropEthernet) property;
                    rxFrameErr = etherProps.getRxFrameErr().getValue();
                    rxOverErr = etherProps.getRxOverErr().getValue();
                    rxCrcErr = etherProps.getRxCrcErr().getValue();
                    collisions = etherProps.getCollisions().getValue();
                    break;
                }
            }
        } else {
            rxFrameErr = entry.getRxFrameErr().getValue();
            rxOverErr = entry.getRxOverErr().getValue();
            rxCrcErr = entry.getRxCrcErr().getValue();
            collisions = entry.getCollisions().getValue();
        }
        return new PortStatsEntry(entry.getPortNo().getPortNumber(), entry.getRxPackets().getValue(), entry.getTxPackets().getValue(), entry.getRxBytes().getValue(), entry.getTxBytes().getValue(), entry.getRxDropped().getValue(), entry.getTxDropped().getValue(), entry.getRxErrors().getValue(), entry.getTxErrors().getValue(), rxFrameErr, rxOverErr, rxCrcErr, collisions);
    } catch (NullPointerException | UnsupportedOperationException | IllegalArgumentException e) {
        log.error(String.format("Could not OFPortStatsEntry OFMeterStats object %s", entry), e);
        return null;
    }
}
Also used : OFPortStatsPropEthernet(org.projectfloodlight.openflow.protocol.OFPortStatsPropEthernet) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) OFPortStatsProp(org.projectfloodlight.openflow.protocol.OFPortStatsProp)

Example 3 with OFPortStatsEntry

use of org.projectfloodlight.openflow.protocol.OFPortStatsEntry in project open-kilda by telstra.

the class OfPortStatsMapperTest method testToPortStatsDataV14.

@Test
public void testToPortStatsDataV14() {
    OFFactoryVer14 ofFactoryVer14 = new OFFactoryVer14();
    OFPortStatsProp opticalProps = ofFactoryVer14.buildPortStatsPropOptical().setRxPwr(123).build();
    OFPortStatsProp ethernetProps = ofFactoryVer14.buildPortStatsPropEthernet().setRxFrameErr(U64.of(rxFrameErr)).setRxOverErr(U64.of(rxOverErr)).setRxCrcErr(U64.of(rxCrcErr)).setCollisions(U64.of(collisions)).build();
    OFPortStatsEntry ofPortStatsEntry = prebuildPortStatsEntry(ofFactoryVer14.buildPortStatsEntry()).setProperties(Lists.newArrayList(opticalProps, ethernetProps)).build();
    OFPortStatsReply ofPortStatsReply = ofFactoryVer14.buildPortStatsReply().setXid(xId).setEntries(Collections.singletonList(ofPortStatsEntry)).build();
    PortStatsData data = OfPortStatsMapper.INSTANCE.toPostStatsData(Collections.singletonList(ofPortStatsReply), switchId);
    assertPortStatsData(data);
}
Also used : OFFactoryVer14(org.projectfloodlight.openflow.protocol.ver14.OFFactoryVer14) OFPortStatsReply(org.projectfloodlight.openflow.protocol.OFPortStatsReply) OFPortStatsEntry(org.projectfloodlight.openflow.protocol.OFPortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) OFPortStatsProp(org.projectfloodlight.openflow.protocol.OFPortStatsProp) Test(org.junit.Test)

Aggregations

OFPortStatsEntry (org.projectfloodlight.openflow.protocol.OFPortStatsEntry)3 Test (org.junit.Test)2 PortStatsData (org.openkilda.messaging.info.stats.PortStatsData)2 OFPortStatsProp (org.projectfloodlight.openflow.protocol.OFPortStatsProp)2 OFPortStatsReply (org.projectfloodlight.openflow.protocol.OFPortStatsReply)2 PortStatsEntry (org.openkilda.messaging.info.stats.PortStatsEntry)1 OFPortStatsPropEthernet (org.projectfloodlight.openflow.protocol.OFPortStatsPropEthernet)1 OFFactoryVer13 (org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13)1 OFFactoryVer14 (org.projectfloodlight.openflow.protocol.ver14.OFFactoryVer14)1