Search in sources :

Example 1 with FloodlightModuleContext

use of net.floodlightcontroller.core.module.FloodlightModuleContext in project open-kilda by telstra.

the class StatisticsService method startUp.

@Override
public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
    if (interval > 0) {
        threadPoolService.getScheduledExecutor().scheduleAtFixedRate(() -> switchService.getAllSwitchMap().values().forEach(iofSwitch -> {
            OFFactory factory = iofSwitch.getOFFactory();
            final String switchId = iofSwitch.getId().toString();
            OFPortStatsRequest portStatsRequest = factory.buildPortStatsRequest().setPortNo(OFPort.ANY).build();
            OFFlowStatsRequest flowStatsRequest = factory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(SYSTEM_MASK).build();
            logger.info("Getting port stats for switch={}", iofSwitch.getId());
            Futures.addCallback(iofSwitch.writeStatsRequest(portStatsRequest), new RequestCallback<>(data -> {
                List<PortStatsReply> replies = data.stream().map(reply -> {
                    List<PortStatsEntry> entries = reply.getEntries().stream().map(entry -> {
                        if (entry.getVersion().compareTo(OFVersion.OF_13) > 0) {
                            long rxFrameErr, rxOverErr, rxCrcErr, collisions;
                            rxFrameErr = rxOverErr = rxCrcErr = collisions = 0;
                            for (OFPortStatsProp property : entry.getProperties()) {
                                if (property.getType() == 0x0) {
                                    OFPortStatsPropEthernet etherProps = (OFPortStatsPropEthernet) property;
                                    rxFrameErr = etherProps.getRxFrameErr().getValue();
                                    rxOverErr = etherProps.getRxOverErr().getValue();
                                    rxCrcErr = etherProps.getRxCrcErr().getValue();
                                    collisions = etherProps.getCollisions().getLength();
                                }
                            }
                            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);
                        } else {
                            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(), entry.getRxFrameErr().getValue(), entry.getRxOverErr().getValue(), entry.getRxCrcErr().getValue(), entry.getCollisions().getValue());
                        }
                    }).collect(toList());
                    return new PortStatsReply(reply.getXid(), entries);
                }).collect(toList());
                return new PortStatsData(switchId, replies);
            }, "port"));
            if (factory.getVersion().compareTo(OFVersion.OF_15) != 0) {
                // skip flow stats for OF 1.5 protocol version
                logger.info("Getting flow stats for switch={}", iofSwitch.getId());
                Futures.addCallback(iofSwitch.writeStatsRequest(flowStatsRequest), new RequestCallback<>(data -> {
                    List<FlowStatsReply> replies = data.stream().map(reply -> {
                        List<FlowStatsEntry> entries = reply.getEntries().stream().map(entry -> new FlowStatsEntry(entry.getTableId().getValue(), entry.getCookie().getValue(), entry.getPacketCount().getValue(), entry.getByteCount().getValue())).collect(toList());
                        return new FlowStatsReply(reply.getXid(), entries);
                    }).collect(toList());
                    return new FlowStatsData(switchId, replies);
                }, "flow"));
            }
        }), interval, interval, TimeUnit.SECONDS);
    }
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) OFVersion(org.projectfloodlight.openflow.protocol.OFVersion) U64(org.projectfloodlight.openflow.types.U64) OFStatsReply(org.projectfloodlight.openflow.protocol.OFStatsReply) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) LoggerFactory(org.slf4j.LoggerFactory) IOFSwitchService(net.floodlightcontroller.core.internal.IOFSwitchService) Function(java.util.function.Function) ArrayList(java.util.ArrayList) OFPortStatsProp(org.projectfloodlight.openflow.protocol.OFPortStatsProp) Map(java.util.Map) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) Logger(org.slf4j.Logger) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) Collection(java.util.Collection) InfoData(org.openkilda.messaging.info.InfoData) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) FloodlightModuleException(net.floodlightcontroller.core.module.FloodlightModuleException) IFloodlightModule(net.floodlightcontroller.core.module.IFloodlightModule) FutureCallback(com.google.common.util.concurrent.FutureCallback) TimeUnit(java.util.concurrent.TimeUnit) OFPort(org.projectfloodlight.openflow.types.OFPort) Collectors.toList(java.util.stream.Collectors.toList) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Topic(org.openkilda.messaging.Topic) IFloodlightService(net.floodlightcontroller.core.module.IFloodlightService) KafkaMessageProducer(org.openkilda.floodlight.kafka.KafkaMessageProducer) Destination(org.openkilda.messaging.Destination) IFloodlightProviderService(net.floodlightcontroller.core.IFloodlightProviderService) SYSTEM_CORRELATION_ID(org.openkilda.messaging.Utils.SYSTEM_CORRELATION_ID) Collections(java.util.Collections) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) IThreadPoolService(net.floodlightcontroller.threadpool.IThreadPoolService) OFPortStatsPropEthernet(org.projectfloodlight.openflow.protocol.OFPortStatsPropEthernet) OFGroup(org.projectfloodlight.openflow.types.OFGroup) OFPortStatsPropEthernet(org.projectfloodlight.openflow.protocol.OFPortStatsPropEthernet) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) PortStatsReply(org.openkilda.messaging.info.stats.PortStatsReply) FlowStatsReply(org.openkilda.messaging.info.stats.FlowStatsReply) FlowStatsEntry(org.openkilda.messaging.info.stats.FlowStatsEntry) FlowStatsData(org.openkilda.messaging.info.stats.FlowStatsData) OFPortStatsRequest(org.projectfloodlight.openflow.protocol.OFPortStatsRequest) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) PortStatsEntry(org.openkilda.messaging.info.stats.PortStatsEntry) PortStatsData(org.openkilda.messaging.info.stats.PortStatsData) OFPortStatsProp(org.projectfloodlight.openflow.protocol.OFPortStatsProp)

Example 2 with FloodlightModuleContext

use of net.floodlightcontroller.core.module.FloodlightModuleContext in project open-kilda by telstra.

the class PathTest method setUp.

@Before
public void setUp() throws Exception {
    cntx = new FloodlightContext();
    FloodlightModuleContext fmc = new FloodlightModuleContext();
    fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
    fmc.addService(IOFSwitchService.class, getMockSwitchService());
    swDescription = factory.buildDescStatsReply().build();
    swFeatures = factory.buildFeaturesReply().setNBuffers(1000).build();
    sw1Port1 = EasyMock.createMock(OFPortDesc.class);
    sw2Port1 = EasyMock.createMock(OFPortDesc.class);
    expect(sw1Port1.getHwAddr()).andReturn(MacAddress.of(sw1HwAddrTarget)).anyTimes();
    expect(sw1Port1.getPortNo()).andReturn(OFPort.of(1));
    expect(sw2Port1.getHwAddr()).andReturn(MacAddress.of(sw2HwAddrTarget)).anyTimes();
    expect(sw2Port1.getPortNo()).andReturn(OFPort.of(1));
    sw1 = EasyMock.createMock(IOFSwitch.class);
    expect(sw1.getId()).andReturn(sw1Id).anyTimes();
    expect(sw1.getPort(OFPort.of(1))).andReturn(sw1Port1).anyTimes();
    expect(sw1.getOFFactory()).andReturn(factory).anyTimes();
    expect(sw1.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
    expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
    expect(sw1.getSwitchDescription()).andReturn(new SwitchDescription(swDescription)).anyTimes();
    expect(sw1.isActive()).andReturn(true).anyTimes();
    expect(sw1.getLatency()).andReturn(U64.of(10L)).anyTimes();
    expect(sw1.getInetAddress()).andReturn(sw1InetAddr).anyTimes();
    sw2 = EasyMock.createMock(IOFSwitch.class);
    expect(sw2.getId()).andReturn(sw2Id).anyTimes();
    expect(sw2.getPort(OFPort.of(1))).andReturn(sw1Port1).anyTimes();
    expect(sw2.getOFFactory()).andReturn(factory).anyTimes();
    expect(sw2.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
    expect(sw2.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
    expect(sw2.getSwitchDescription()).andReturn(new SwitchDescription(swDescription)).anyTimes();
    expect(sw2.isActive()).andReturn(true).anyTimes();
    expect(sw2.getLatency()).andReturn(U64.of(10L)).anyTimes();
    expect(sw2.getInetAddress()).andReturn(sw2InetAddr).anyTimes();
    replay(sw1Port1);
    replay(sw2Port1);
    replay(sw1);
    replay(sw2);
    packetIn = EasyMock.createMock(OFPacketIn.class);
    pvs.initAlgorithm("secret");
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) OFPacketIn(org.projectfloodlight.openflow.protocol.OFPacketIn) SwitchDescription(net.floodlightcontroller.core.SwitchDescription) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Before(org.junit.Before)

Example 3 with FloodlightModuleContext

use of net.floodlightcontroller.core.module.FloodlightModuleContext in project open-kilda by telstra.

the class PathVerificationPacketInTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    cntx = new FloodlightContext();
    mockFloodlightProvider = getMockFloodlightProvider();
    swFeatures = factory.buildFeaturesReply().setNBuffers(1000).build();
    swDescription = factory.buildDescStatsReply().build();
    FloodlightModuleContext fmc = new FloodlightModuleContext();
    fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
    fmc.addService(IOFSwitchService.class, getMockSwitchService());
    OFPacketIn.Builder packetInBuilder = factory.buildPacketIn();
    packetInBuilder.setMatch(factory.buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build()).setData(pkt).setReason(OFPacketInReason.NO_MATCH);
    pktIn = packetInBuilder.build();
    System.out.print(Hex.encodeHexString(pktIn.getData()));
    pvs = new PathVerificationService();
    fmc.addConfigParam(pvs, "isl_bandwidth_quotient", "0.0");
    fmc.addConfigParam(pvs, "hmac256-secret", "secret");
    fmc.addConfigParam(pvs, "bootstrap-servers", "");
    pvs.initServices(fmc);
    pvs.initAlgorithm("secret");
    srcIpTarget = new InetSocketAddress("192.168.10.1", 200);
    dstIpTarget = new InetSocketAddress("192.168.10.101", 100);
    sw1HwAddrTarget = "11:22:33:44:55:66";
    sw2HwAddrTarget = "AA:BB:CC:DD:EE:FF";
    OFPortDesc sw1Port1 = EasyMock.createMock(OFPortDesc.class);
    expect(sw1Port1.getHwAddr()).andReturn(MacAddress.of(sw1HwAddrTarget)).anyTimes();
    expect(sw1Port1.getVersion()).andReturn(OFVersion.OF_12).anyTimes();
    expect(sw1Port1.getCurrSpeed()).andReturn(100000L).anyTimes();
    OFPortDesc sw2Port1 = EasyMock.createMock(OFPortDesc.class);
    expect(sw2Port1.getHwAddr()).andReturn(MacAddress.of(sw2HwAddrTarget)).anyTimes();
    expect(sw2Port1.getVersion()).andReturn(OFVersion.OF_12).anyTimes();
    expect(sw2Port1.getCurrSpeed()).andReturn(100000L).anyTimes();
    replay(sw1Port1);
    replay(sw2Port1);
    sw1 = buildMockIOFSwitch(1L, sw1Port1, factory, swDescription, srcIpTarget);
    sw2 = buildMockIOFSwitch(2L, sw2Port1, factory, swDescription, dstIpTarget);
    replay(sw1);
    replay(sw2);
}
Also used : OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InetSocketAddress(java.net.InetSocketAddress) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) OFPacketIn(org.projectfloodlight.openflow.protocol.OFPacketIn) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Before(org.junit.Before)

Example 4 with FloodlightModuleContext

use of net.floodlightcontroller.core.module.FloodlightModuleContext in project open-kilda by telstra.

the class PathVerificationPacketOutTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    cntx = new FloodlightContext();
    FloodlightModuleContext fmc = new FloodlightModuleContext();
    fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
    fmc.addService(IOFSwitchService.class, getMockSwitchService());
    swDescription = factory.buildDescStatsReply().build();
    pvs = new PathVerificationService();
    pvs.initAlgorithm("secret");
    srcIpTarget = new InetSocketAddress("192.168.10.1", 200);
    dstIpTarget = new InetSocketAddress("192.168.10.101", 100);
    sw1HwAddrTarget = "11:22:33:44:55:66";
    sw2HwAddrTarget = "AA:BB:CC:DD:EE:FF";
    OFPortDesc sw1Port1 = EasyMock.createMock(OFPortDesc.class);
    expect(sw1Port1.getHwAddr()).andReturn(MacAddress.of(sw1HwAddrTarget)).anyTimes();
    OFPortDesc sw2Port1 = EasyMock.createMock(OFPortDesc.class);
    expect(sw2Port1.getHwAddr()).andReturn(MacAddress.of(sw2HwAddrTarget)).anyTimes();
    replay(sw1Port1);
    replay(sw2Port1);
    sw1 = buildMockIOFSwitch(1L, sw1Port1, factory, swDescription, srcIpTarget);
    sw2 = buildMockIOFSwitch(2L, sw2Port1, factory, swDescription, dstIpTarget);
    replay(sw1);
    replay(sw2);
}
Also used : OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InetSocketAddress(java.net.InetSocketAddress) FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Before(org.junit.Before)

Example 5 with FloodlightModuleContext

use of net.floodlightcontroller.core.module.FloodlightModuleContext in project open-kilda by telstra.

the class KafkaMessageProducer method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(FloodlightModuleContext moduleContext) throws FloodlightModuleException {
    Context context = new Context(moduleContext, this);
    initProducer(context);
    initHeartBeat(context);
}
Also used : FloodlightModuleContext(net.floodlightcontroller.core.module.FloodlightModuleContext)

Aggregations

FloodlightModuleContext (net.floodlightcontroller.core.module.FloodlightModuleContext)6 FloodlightContext (net.floodlightcontroller.core.FloodlightContext)4 Before (org.junit.Before)4 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)3 InetSocketAddress (java.net.InetSocketAddress)2 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)2 SwitchDescription (net.floodlightcontroller.core.SwitchDescription)2 OFPacketIn (org.projectfloodlight.openflow.protocol.OFPacketIn)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 Collectors.toList (java.util.stream.Collectors.toList)1 IFloodlightProviderService (net.floodlightcontroller.core.IFloodlightProviderService)1 IOFSwitchService (net.floodlightcontroller.core.internal.IOFSwitchService)1