Search in sources :

Example 1 with OFFlowStatsEntry

use of org.projectfloodlight.openflow.protocol.OFFlowStatsEntry 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 2 with OFFlowStatsEntry

use of org.projectfloodlight.openflow.protocol.OFFlowStatsEntry 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 3 with OFFlowStatsEntry

use of org.projectfloodlight.openflow.protocol.OFFlowStatsEntry 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

OFFlowStatsEntry (org.projectfloodlight.openflow.protocol.OFFlowStatsEntry)3 OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)1 MessageError (org.openkilda.messaging.error.MessageError)1 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)1 OFFlowDelete (org.projectfloodlight.openflow.protocol.OFFlowDelete)1 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)1 OFFlowStatsRequest (org.projectfloodlight.openflow.protocol.OFFlowStatsRequest)1 Get (org.restlet.resource.Get)1