Search in sources :

Example 11 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class RecordHandler method processInstallServer42IslRttRule.

private Long processInstallServer42IslRttRule(SwitchId switchId, long cookie, int server42Port, int server42Vlan, MacAddress server42MacAddress) throws SwitchOperationException {
    ISwitchManager switchManager = context.getSwitchManager();
    DatapathId dpid = DatapathId.of(switchId.toLong());
    if (cookie == SERVER_42_ISL_RTT_OUTPUT_COOKIE) {
        return switchManager.installServer42IslRttOutputFlow(dpid, server42Port, server42Vlan, server42MacAddress);
    } else if (new Cookie(cookie).getType() == CookieType.SERVER_42_ISL_RTT_INPUT) {
        PortColourCookie portColourCookie = new PortColourCookie(cookie);
        int islPort = portColourCookie.getPortNumber();
        return switchManager.installServer42IslRttInputFlow(dpid, server42Port, islPort);
    } else {
        logger.warn("Skipping the installation of unexpected server 42 switch rule {} for switch {}", Long.toHexString(cookie), switchId);
        return null;
    }
}
Also used : FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) Cookie(org.openkilda.model.cookie.Cookie) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) DatapathId(org.projectfloodlight.openflow.types.DatapathId) PortColourCookie(org.openkilda.model.cookie.PortColourCookie)

Example 12 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class RecordHandler method processInstallServer42RttRule.

private void processInstallServer42RttRule(InstallServer42Flow command) throws SwitchOperationException {
    ISwitchManager switchManager = context.getSwitchManager();
    DatapathId dpid = DatapathId.of(command.getSwitchId().toLong());
    Cookie cookie = new Cookie(command.getCookie());
    FlowSharedSegmentCookie sharedSegmentCookie = new FlowSharedSegmentCookie(command.getCookie());
    if (command.getCookie() == SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE) {
        switchManager.installServer42FlowRttOutputVlanFlow(dpid, command.getOutputPort(), command.getServer42Vlan(), command.getServer42MacAddress());
    } else if (command.getCookie() == SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE) {
        switchManager.installServer42FlowRttOutputVxlanFlow(dpid, command.getOutputPort(), command.getServer42Vlan(), command.getServer42MacAddress());
    } else if (cookie.getType() == CookieType.SERVER_42_FLOW_RTT_INPUT) {
        PortColourCookie portColourCookie = new PortColourCookie(command.getCookie());
        int customerPort = portColourCookie.getPortNumber();
        switchManager.installServer42FlowRttInputFlow(dpid, command.getInputPort(), customerPort, command.getServer42MacAddress());
    } else if (cookie.getType() == CookieType.SHARED_OF_FLOW && sharedSegmentCookie.getSegmentType() == SharedSegmentType.SERVER42_QINQ_OUTER_VLAN) {
        switchManager.installServer42OuterVlanMatchSharedFlow(dpid, sharedSegmentCookie);
    } else if (command.getCookie() == SERVER_42_ISL_RTT_OUTPUT_COOKIE) {
        processInstallServer42IslRttRule(command.getSwitchId(), command.getCookie(), command.getOutputPort(), command.getServer42Vlan(), command.getServer42MacAddress());
    } else if (cookie.getType() == CookieType.SERVER_42_ISL_RTT_INPUT) {
        processInstallServer42IslRttRule(command.getSwitchId(), command.getCookie(), command.getInputPort(), command.getServer42Vlan(), command.getServer42MacAddress());
    } else {
        logger.warn("Skipping the installation of unexpected server 42 switch rule {} for switch {}", Long.toHexString(command.getCookie()), command.getSwitchId());
    }
}
Also used : FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) Cookie(org.openkilda.model.cookie.Cookie) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) FlowSharedSegmentCookie(org.openkilda.model.cookie.FlowSharedSegmentCookie) DatapathId(org.projectfloodlight.openflow.types.DatapathId) PortColourCookie(org.openkilda.model.cookie.PortColourCookie) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 13 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class RecordHandler method doDeleteMeter.

private void doDeleteMeter(CommandMessage message, String replyToTopic) {
    DeleteMeterRequest request = (DeleteMeterRequest) message.getData();
    logger.info("Deleting meter '{}'. Switch: '{}'", request.getMeterId(), request.getSwitchId());
    final IKafkaProducerService producerService = getKafkaProducer();
    try {
        DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
        context.getSwitchManager().deleteMeter(dpid, request.getMeterId());
        boolean deleted = context.getSwitchManager().dumpMeters(dpid).stream().noneMatch(config -> config.getMeterId() == request.getMeterId());
        DeleteMeterResponse response = new DeleteMeterResponse(deleted);
        InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
        producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
    } catch (SwitchOperationException e) {
        logger.error("Deleting meter '{}' from switch '{}' was unsuccessful: {}", request.getMeterId(), request.getSwitchId(), e.getMessage());
        anError(ErrorType.DATA_INVALID).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
    }
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) IKafkaProducerService(org.openkilda.floodlight.service.kafka.IKafkaProducerService) InfoMessage(org.openkilda.messaging.info.InfoMessage) DeleteMeterResponse(org.openkilda.messaging.info.switches.DeleteMeterResponse) DatapathId(org.projectfloodlight.openflow.types.DatapathId) DeleteMeterRequest(org.openkilda.messaging.command.flow.DeleteMeterRequest)

Example 14 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class RecordHandler method doRemoveIslDefaultRule.

private void doRemoveIslDefaultRule(CommandMessage message) {
    RemoveIslDefaultRulesCommand toRemove = (RemoveIslDefaultRulesCommand) message.getData();
    RemoveIslDefaultRulesResult result = new RemoveIslDefaultRulesResult(toRemove.getSrcSwitch(), toRemove.getSrcPort(), toRemove.getDstSwitch(), toRemove.getDstPort(), true);
    DatapathId dpid = DatapathId.of(toRemove.getSrcSwitch().toLong());
    try {
        context.getSwitchManager().removeMultitableEndpointIslRules(dpid, toRemove.getSrcPort());
        context.getSwitchManager().removeServer42IslRttInputFlow(dpid, toRemove.getSrcPort());
    } catch (SwitchOperationException e) {
        logger.error("Failed to remove isl rules for switch: '{}'", toRemove.getSrcSwitch(), e);
        result.setSuccess(false);
    }
    getKafkaProducer().sendMessageAndTrack(context.getKafkaSwitchManagerTopic(), record.key(), new InfoMessage(result, System.currentTimeMillis(), message.getCorrelationId(), context.getRegion()));
}
Also used : SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) RemoveIslDefaultRulesResult(org.openkilda.messaging.info.discovery.RemoveIslDefaultRulesResult) InfoMessage(org.openkilda.messaging.info.InfoMessage) DatapathId(org.projectfloodlight.openflow.types.DatapathId) RemoveIslDefaultRulesCommand(org.openkilda.messaging.payload.switches.RemoveIslDefaultRulesCommand)

Example 15 with DatapathId

use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.

the class RecordHandler method doPortsCommandDataRequest.

private void doPortsCommandDataRequest(Set<SwitchId> scope, PortsCommandData payload, String correlationId) {
    ISwitchManager switchManager = context.getModuleContext().getServiceImpl(ISwitchManager.class);
    try {
        logger.info("Getting ports data. Requester: {}", payload.getRequester());
        Map<DatapathId, IOFSwitch> allSwitchMap = context.getSwitchManager().getAllSwitchMap(true);
        for (Map.Entry<DatapathId, IOFSwitch> entry : allSwitchMap.entrySet()) {
            SwitchId switchId = new SwitchId(entry.getKey().toString());
            if (!scope.contains(switchId)) {
                continue;
            }
            try {
                IOFSwitch sw = entry.getValue();
                Set<PortStatusData> statuses = new HashSet<>();
                for (OFPortDesc portDesc : switchManager.getPhysicalPorts(sw.getId())) {
                    statuses.add(new PortStatusData(portDesc.getPortNo().getPortNumber(), portDesc.isEnabled() ? PortStatus.UP : PortStatus.DOWN));
                }
                SwitchPortStatusData response = SwitchPortStatusData.builder().switchId(switchId).ports(statuses).requester(payload.getRequester()).build();
                InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), correlationId);
                getKafkaProducer().sendMessageAndTrack(context.getKafkaStatsTopic(), infoMessage);
            } catch (Exception e) {
                logger.error("Could not get port stats data for switch '{}' with error '{}'", switchId, e.getMessage(), e);
            }
        }
    } catch (Exception e) {
        logger.error("Could not get port data for stats '{}'", e.getMessage(), e);
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) InvalidMeterIdException(org.openkilda.floodlight.error.InvalidMeterIdException) IOException(java.io.IOException) SwitchOperationException(org.openkilda.floodlight.error.SwitchOperationException) SwitchNotFoundException(org.openkilda.floodlight.error.SwitchNotFoundException) OfInstallException(org.openkilda.floodlight.error.OfInstallException) FlowCommandException(org.openkilda.floodlight.error.FlowCommandException) UnsupportedSwitchOperationException(org.openkilda.floodlight.error.UnsupportedSwitchOperationException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) PortStatusData(org.openkilda.messaging.info.stats.PortStatusData) SwitchPortStatusData(org.openkilda.messaging.info.stats.SwitchPortStatusData) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) InfoMessage(org.openkilda.messaging.info.InfoMessage) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

DatapathId (org.projectfloodlight.openflow.types.DatapathId)55 InfoMessage (org.openkilda.messaging.info.InfoMessage)19 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)17 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)16 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)16 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)16 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)15 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)14 SwitchId (org.openkilda.model.SwitchId)14 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)13 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)12 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)10 ArrayList (java.util.ArrayList)9 InetSocketAddress (java.net.InetSocketAddress)8 HashSet (java.util.HashSet)8 Map (java.util.Map)8 InvalidMeterIdException (org.openkilda.floodlight.error.InvalidMeterIdException)8 OfInstallException (org.openkilda.floodlight.error.OfInstallException)8 Objects (java.util.Objects)7 Collectors (java.util.stream.Collectors)7