use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class RecordHandler method doConfigurePort.
private void doConfigurePort(final CommandMessage message) {
PortConfigurationRequest request = (PortConfigurationRequest) message.getData();
logger.info("Port configuration request. Switch '{}', Port '{}'", request.getSwitchId(), request.getPortNumber());
final IKafkaProducerService producerService = getKafkaProducer();
final String replyToTopic = context.getKafkaNorthboundTopic();
try {
ISwitchManager switchManager = context.getSwitchManager();
DatapathId dpId = DatapathId.of(request.getSwitchId().toLong());
switchManager.configurePort(dpId, request.getPortNumber(), request.getAdminDown());
InfoMessage infoMessage = new InfoMessage(new PortConfigurationResponse(request.getSwitchId(), request.getPortNumber()), message.getTimestamp(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, infoMessage);
} catch (SwitchOperationException e) {
logger.error("Port configuration request failed. " + e.getMessage(), e);
anError(ErrorType.DATA_INVALID).withMessage(e.getMessage()).withDescription("Port configuration request failed").withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class RecordHandler method doModifyMeterRequest.
private void doModifyMeterRequest(CommandMessage message) {
MeterModifyCommandRequest request = (MeterModifyCommandRequest) message.getData();
final IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaNbWorkerTopic();
SwitchId switchId = request.getSwitchId();
DatapathId datapathId = DatapathId.of(switchId.toLong());
long meterId = request.getMeterId();
ISwitchManager switchManager = context.getSwitchManager();
try {
switchManager.modifyMeterForFlow(datapathId, meterId, request.getBandwidth());
MeterEntry meterEntry = OfMeterConverter.toMeterEntry(switchManager.dumpMeterById(datapathId, meterId));
SwitchMeterEntries response = SwitchMeterEntries.builder().switchId(switchId).meterEntries(ImmutableList.of(meterEntry)).build();
InfoMessage infoMessage = new InfoMessage(response, message.getTimestamp(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), infoMessage);
} catch (UnsupportedSwitchOperationException e) {
String messageString = String.format("Not supported: %s", new SwitchId(e.getDpId().getLong()));
logger.error(messageString, e);
anError(ErrorType.PARAMETERS_INVALID).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchNotFoundException e) {
logger.error("Update switch meters is unsuccessful. Switch {} not found", new SwitchId(e.getDpId().getLong()));
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(new SwitchId(e.getDpId().getLong()).toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
} catch (SwitchOperationException e) {
String messageString = "Unable to update meter";
logger.error(messageString, e);
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(messageString).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class PingResponseCommandTest method success.
@Test
public void success() throws Exception {
final PingService realPingService = new PingService();
moduleContext.addService(PingService.class, realPingService);
final ISwitchManager realSwitchManager = new SwitchManager();
moduleContext.addService(ISwitchManager.class, realSwitchManager);
InputService inputService = createMock(InputService.class);
moduleContext.addService(InputService.class, inputService);
inputService.addTranslator(eq(OFType.PACKET_IN), anyObject());
replayAll();
final DatapathId dpIdBeta = DatapathId.of(0x0000fffe000002L);
final Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 8), new NetworkEndpoint(new SwitchId(dpId.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 3);
final PingData payload = PingData.of(ping);
moduleContext.addConfigParam(new PathVerificationService(), "hmac256-secret", "secret");
realPingService.setup(moduleContext);
byte[] signedPayload = realPingService.getSignature().sign(payload);
byte[] wireData = realPingService.wrapData(ping, signedPayload).serialize();
OFFactory ofFactory = new OFFactoryVer13();
OFPacketIn message = ofFactory.buildPacketIn().setReason(OFPacketInReason.ACTION).setXid(1L).setCookie(PingService.OF_CATCH_RULE_COOKIE).setData(wireData).build();
FloodlightContext metadata = new FloodlightContext();
IPacket decodedEthernet = new Ethernet().deserialize(wireData, 0, wireData.length);
Assert.assertTrue(decodedEthernet instanceof Ethernet);
IFloodlightProviderService.bcStore.put(metadata, IFloodlightProviderService.CONTEXT_PI_PAYLOAD, (Ethernet) decodedEthernet);
OfInput input = new OfInput(iofSwitch, message, metadata);
final PingResponseCommand command = makeCommand(input);
command.call();
final List<Message> replies = kafkaMessageCatcher.getValues();
Assert.assertEquals(1, replies.size());
InfoMessage response = (InfoMessage) replies.get(0);
PingResponse pingResponse = (PingResponse) response.getData();
Assert.assertNull(pingResponse.getError());
Assert.assertNotNull(pingResponse.getMeters());
Assert.assertEquals(payload.getPingId(), pingResponse.getPingId());
}
use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class FlowsResource method getFlows.
/**
* The method returns the flow for the switch from the request.
*/
@Get("json")
@SuppressWarnings("unchecked")
public Map<String, Object> getFlows() throws SwitchOperationException {
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 {
List<OFFlowStatsEntry> flowEntries = switchManager.dumpFlowTable(DatapathId.of(switchId));
LOGGER.debug("OF_STATS: {}", flowEntries);
if (flowEntries != null) {
for (OFFlowStatsEntry entry : flowEntries) {
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(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
}
return response;
}
use of org.openkilda.floodlight.switchmanager.ISwitchManager in project open-kilda by telstra.
the class MetersResource method getMeters.
// FIXME(surabujin): is it used anywhere?
/**
* Gets meters.
* @return the map of meters.
*/
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
Map<Long, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
logger.debug("Get meters for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
List<OFMeterConfig> meters = switchManager.dumpMeters(DatapathId.of(switchId));
if (meters != null) {
logger.debug("Meters from switch {} received: {}", switchId, meters.size());
for (OFMeterConfig entry : meters) {
response.put(entry.getMeterId(), entry);
}
}
} catch (UnsupportedSwitchOperationException ex) {
String messageString = "Not supported";
logger.error("{}: {}", messageString, switchId, ex);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, ex.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
} catch (IllegalArgumentException | SwitchOperationException exception) {
String messageString = "No such switch";
logger.error("{}: {}", messageString, switchId, exception);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
}
return response;
}
Aggregations