use of org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest in project open-kilda by telstra.
the class CommandBuilderImplTest method reinstallServer42RuleTest.
@Test
public void reinstallServer42RuleTest() {
List<ReinstallDefaultFlowForSwitchManagerRequest> commands = commandBuilder.buildCommandsToReinstallRules(SWITCH_ID_A, Lists.newArrayList(Cookie.SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE));
assertEquals(1, commands.size());
assertEquals(ReinstallServer42FlowForSwitchManagerRequest.class, commands.get(0).getClass());
ReinstallServer42FlowForSwitchManagerRequest server42Command = (ReinstallServer42FlowForSwitchManagerRequest) commands.get(0);
assertEquals(SERVER42_MAC_ADDRESS, server42Command.getServer42MacAddress());
assertEquals(SERVER42_PORT, server42Command.getServer42Port());
assertEquals(SERVER42_VLAN, server42Command.getServer42Vlan());
}
use of org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest in project open-kilda by telstra.
the class RecordHandlerTest method reinstallServer42FlowRttOutputVlanTest.
@Test
public void reinstallServer42FlowRttOutputVlanTest() throws SwitchOperationException {
long cookie = SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE;
expect(switchManager.installServer42FlowRttOutputVlanFlow(DATAPATH_ID, SERVER42_PORT, SERVER42_VLAN, SERVER42_MAC_ADDRESS)).andReturn(cookie).once();
expect(switchManager.deleteRulesByCriteria(DATAPATH_ID, false, null, DeleteRulesCriteria.builder().cookie(cookie).build())).andReturn(Lists.newArrayList(cookie)).once();
replay(switchManager);
ReinstallServer42FlowForSwitchManagerRequest request = new ReinstallServer42FlowForSwitchManagerRequest(SWITCH_ID, cookie, SERVER42_MAC_ADDRESS, SERVER42_VLAN, SERVER42_PORT);
recordHandler.handleCommand(new CommandMessage(request, 0, null));
verify(switchManager);
}
use of org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest in project open-kilda by telstra.
the class RecordHandlerTest method shouldReinstallServer42IslRttOutputRule.
@Test
public void shouldReinstallServer42IslRttOutputRule() throws SwitchOperationException {
long cookie = SERVER_42_ISL_RTT_OUTPUT_COOKIE;
expect(switchManager.installServer42IslRttOutputFlow(DATAPATH_ID, SERVER42_PORT, SERVER42_VLAN, SERVER42_MAC_ADDRESS)).andReturn(cookie).once();
expect(switchManager.deleteRulesByCriteria(DATAPATH_ID, false, null, DeleteRulesCriteria.builder().cookie(cookie).build())).andReturn(Lists.newArrayList(cookie)).once();
replay(switchManager);
ReinstallServer42FlowForSwitchManagerRequest request = new ReinstallServer42FlowForSwitchManagerRequest(SWITCH_ID, cookie, SERVER42_MAC_ADDRESS, SERVER42_VLAN, SERVER42_PORT);
recordHandler.handleCommand(new CommandMessage(request, 0, null));
verify(switchManager);
}
use of org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest in project open-kilda by telstra.
the class RecordHandlerTest method shouldReinstallServer42IslRttInputRule.
@Test
public void shouldReinstallServer42IslRttInputRule() throws SwitchOperationException {
int islPort = 123;
PortColourCookie cookie = PortColourCookie.builder().portNumber(islPort).type(SERVER_42_ISL_RTT_INPUT).build();
expect(switchManager.installServer42IslRttInputFlow(DATAPATH_ID, SERVER42_PORT, islPort)).andReturn(cookie.getValue()).once();
expect(switchManager.deleteRulesByCriteria(DATAPATH_ID, false, null, DeleteRulesCriteria.builder().cookie(cookie.getValue()).build())).andReturn(Lists.newArrayList(cookie.getValue())).once();
replay(switchManager);
ReinstallServer42FlowForSwitchManagerRequest request = new ReinstallServer42FlowForSwitchManagerRequest(SWITCH_ID, cookie.getValue(), SERVER42_MAC_ADDRESS, SERVER42_VLAN, SERVER42_PORT);
recordHandler.handleCommand(new CommandMessage(request, 0, null));
verify(switchManager);
}
use of org.openkilda.messaging.command.flow.ReinstallServer42FlowForSwitchManagerRequest in project open-kilda by telstra.
the class RecordHandler method doReinstallDefaultFlowForSwitchManager.
/**
* Reinstall default flow.
*
* @param message command message for flow deletion
*/
private void doReinstallDefaultFlowForSwitchManager(CommandMessage message) {
ReinstallDefaultFlowForSwitchManagerRequest request = (ReinstallDefaultFlowForSwitchManagerRequest) message.getData();
IKafkaProducerService producerService = getKafkaProducer();
String replyToTopic = context.getKafkaSwitchManagerTopic();
long cookie = request.getCookie();
if (!Cookie.isDefaultRule(cookie)) {
logger.warn("Failed to reinstall default switch rule for switch: '{}'. Rule {} is not default.", request.getSwitchId(), Long.toHexString(cookie));
anError(ErrorType.DATA_INVALID).withMessage(format("Failed to reinstall default switch rule for switch %s. Rule %s is not default", request.getSwitchId(), Long.toHexString(cookie))).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
SwitchId switchId = request.getSwitchId();
DatapathId dpid = DatapathId.of(switchId.toLong());
try {
RemoveFlow command = RemoveFlow.builder().flowId("REMOVE_DEFAULT_FLOW").cookie(cookie).switchId(switchId).build();
Set<Long> removedFlows = new HashSet<>(processDeleteFlow(command, dpid));
for (Long removedFlow : removedFlows) {
Long installedFlow;
if (request instanceof ReinstallServer42FlowForSwitchManagerRequest) {
installedFlow = processInstallServer42Rule((ReinstallServer42FlowForSwitchManagerRequest) request);
} else {
installedFlow = processInstallDefaultFlowByCookie(switchId, removedFlow);
}
InfoMessage response = new InfoMessage(new FlowReinstallResponse(removedFlow, installedFlow), System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, message.getCorrelationId(), response);
}
} catch (SwitchOperationException e) {
logger.error("Failed to reinstall switch rule for switch: '{}'", request.getSwitchId(), e);
anError(ErrorType.INTERNAL_ERROR).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).sendVia(producerService);
}
}
Aggregations