Search in sources :

Example 1 with OFFlowStatsReply

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

the class RecordHandler method doDumpRulesRequest.

private void doDumpRulesRequest(final CommandMessage message) {
    DumpRulesRequest request = (DumpRulesRequest) message.getData();
    final String switchId = request.getSwitchId();
    logger.debug("Loading installed rules for switch {}", switchId);
    OFFlowStatsReply reply = context.getSwitchManager().dumpFlowTable(DatapathId.of(switchId));
    List<FlowEntry> flows = reply.getEntries().stream().map(OFFlowStatsConverter::toFlowEntry).collect(Collectors.toList());
    SwitchFlowEntries response = SwitchFlowEntries.builder().switchId(switchId).flowEntries(flows).build();
    InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
    context.getKafkaProducer().postMessage(TOPO_ENG_TOPIC, infoMessage);
}
Also used : DumpRulesRequest(org.openkilda.messaging.command.switches.DumpRulesRequest) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) InfoMessage(org.openkilda.messaging.info.InfoMessage) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry)

Example 2 with OFFlowStatsReply

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

the class SwitchManager method deleteAllNonDefaultRules.

@Override
public List<Long> deleteAllNonDefaultRules(final DatapathId dpid) throws SwitchOperationException {
    OFFlowStatsReply flowStats = dumpFlowTable(dpid);
    IOFSwitch sw = lookupSwitch(dpid);
    OFFactory ofFactory = sw.getOFFactory();
    List<Long> removedRules = new ArrayList<>();
    for (OFFlowStatsEntry flowStatsEntry : flowStats.getEntries()) {
        long flowCookie = flowStatsEntry.getCookie().getValue();
        if (flowCookie != DROP_RULE_COOKIE && flowCookie != VERIFICATION_BROADCAST_RULE_COOKIE && flowCookie != VERIFICATION_UNICAST_RULE_COOKIE) {
            OFFlowDelete flowDelete = ofFactory.buildFlowDelete().setCookie(U64.of(flowCookie)).setCookieMask(NON_SYSTEM_MASK).build();
            pushFlow(sw, "--DeleteFlow--", flowDelete);
            removedRules.add(flowCookie);
        }
    }
    return removedRules;
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFFlowDelete(org.projectfloodlight.openflow.protocol.OFFlowDelete) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) ArrayList(java.util.ArrayList) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply)

Example 3 with OFFlowStatsReply

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

the class SwitchManager method dumpFlowTable.

/**
 * {@inheritDoc}
 */
@Override
public OFFlowStatsReply dumpFlowTable(final DatapathId dpid) {
    OFFlowStatsReply values = null;
    IOFSwitch sw = ofSwitchService.getSwitch(dpid);
    if (sw == null) {
        throw new IllegalArgumentException(String.format("Switch %s was not found", dpid.toString()));
    }
    OFFactory ofFactory = sw.getOFFactory();
    OFFlowStatsRequest flowRequest = ofFactory.buildFlowStatsRequest().setOutGroup(OFGroup.ANY).setCookieMask(U64.ZERO).build();
    try {
        ListenableFuture<OFFlowStatsReply> future = sw.writeRequest(flowRequest);
        values = future.get(10, TimeUnit.SECONDS);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        logger.error("Could not get flow stats: {}", e.getMessage());
    }
    return values;
}
Also used : OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) ExecutionException(java.util.concurrent.ExecutionException) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with OFFlowStatsReply

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

the class FlowsResource method getFlows.

@Get("json")
@SuppressWarnings("unchecked")
public Map<String, Object> getFlows() {
    Map<String, Object> response = new HashMap<>();
    String switchId = (String) this.getRequestAttributes().get("switch_id");
    LOGGER.debug("Get flows for switch: {}", switchId);
    ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
    try {
        OFFlowStatsReply replay = switchManager.dumpFlowTable(DatapathId.of(switchId));
        LOGGER.debug("OF_STATS: {}", replay);
        if (replay != null) {
            for (OFFlowStatsEntry entry : replay.getEntries()) {
                String key = String.format("flow-0x%s", Long.toHexString(entry.getCookie().getValue()).toUpperCase());
                response.put(key, buildFlowStat(entry));
            }
        }
    } catch (IllegalArgumentException exception) {
        String messageString = "No such switch";
        LOGGER.error("{}: {}", messageString, switchId, exception);
        MessageError responseMessage = new MessageError(DEFAULT_CORRELATION_ID, System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
        response.putAll(MAPPER.convertValue(responseMessage, Map.class));
    }
    return response;
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) HashMap(java.util.HashMap) MessageError(org.openkilda.messaging.error.MessageError) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) Get(org.restlet.resource.Get)

Example 5 with OFFlowStatsReply

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

the class SwitchManagerTest method shouldDeleteAllNonDefaultRules.

@Test
public void shouldDeleteAllNonDefaultRules() throws Exception {
    // given
    expect(ofSwitchService.getSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    OFFlowStatsEntry ofFlowStatsEntry = mock(OFFlowStatsEntry.class);
    expect(ofFlowStatsEntry.getCookie()).andReturn(U64.of(cookie));
    OFFlowStatsReply ofFlowStatsReply = mock(OFFlowStatsReply.class);
    expect(ofFlowStatsReply.getEntries()).andReturn(singletonList(ofFlowStatsEntry));
    ListenableFuture<OFFlowStatsReply> ofStatsFuture = mock(ListenableFuture.class);
    expect(ofStatsFuture.get(anyLong(), anyObject())).andReturn(ofFlowStatsReply);
    expect(iofSwitch.writeRequest(anyObject(OFFlowStatsRequest.class))).andReturn(ofStatsFuture);
    Capture<OFFlowMod> capture = EasyMock.newCapture();
    expect(iofSwitch.write(capture(capture))).andReturn(true);
    expectLastCall();
    replay(ofSwitchService, iofSwitch, ofFlowStatsEntry, ofFlowStatsReply, ofStatsFuture);
    // when
    switchManager.deleteAllNonDefaultRules(dpid);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(cookie, actual.getCookie().getValue());
    assertEquals(SwitchManager.NON_SYSTEM_MASK, actual.getCookieMask());
}
Also used : OFFlowStatsEntry(org.projectfloodlight.openflow.protocol.OFFlowStatsEntry) OFFlowStatsReply(org.projectfloodlight.openflow.protocol.OFFlowStatsReply) OFFlowStatsRequest(org.projectfloodlight.openflow.protocol.OFFlowStatsRequest) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Aggregations

OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)5 OFFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowStatsEntry)3 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)2 OFFlowStatsRequest (org.projectfloodlight.openflow.protocol.OFFlowStatsRequest)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)1 DumpRulesRequest (org.openkilda.messaging.command.switches.DumpRulesRequest)1 MessageError (org.openkilda.messaging.error.MessageError)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)1 SwitchFlowEntries (org.openkilda.messaging.info.rule.SwitchFlowEntries)1 OFFlowDelete (org.projectfloodlight.openflow.protocol.OFFlowDelete)1 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)1 Get (org.restlet.resource.Get)1