use of org.openkilda.model.MacAddress in project open-kilda by telstra.
the class RuleManagerImpl method getServiceRuleGenerators.
@VisibleForTesting
List<RuleGenerator> getServiceRuleGenerators(SwitchId switchId, DataAdapter adapter) {
List<RuleGenerator> generators = new ArrayList<>();
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(DROP_RULE_COOKIE), OfTable.INPUT));
generators.add(serviceRulesFactory.getUniCastDiscoveryRuleGenerator());
generators.add(serviceRulesFactory.getBroadCastDiscoveryRuleGenerator());
generators.add(serviceRulesFactory.getDropDiscoveryLoopRuleGenerator());
generators.add(serviceRulesFactory.getBfdCatchRuleGenerator());
generators.add(serviceRulesFactory.getRoundTripLatencyRuleGenerator());
generators.add(serviceRulesFactory.getUnicastVerificationVxlanRuleGenerator());
SwitchProperties switchProperties = adapter.getSwitchProperties(switchId);
if (switchProperties.isMultiTable()) {
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_INGRESS_DROP_COOKIE), OfTable.INGRESS));
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_TRANSIT_DROP_COOKIE), OfTable.TRANSIT));
generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_POST_INGRESS_DROP_COOKIE), OfTable.POST_INGRESS));
generators.add(serviceRulesFactory.getTablePassThroughDefaultRuleGenerator(new Cookie(MULTITABLE_EGRESS_PASS_THROUGH_COOKIE), OfTable.TRANSIT, OfTable.EGRESS));
generators.add(serviceRulesFactory.getTablePassThroughDefaultRuleGenerator(new Cookie(MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE), OfTable.INGRESS, OfTable.PRE_INGRESS));
generators.add(serviceRulesFactory.getLldpPostIngressRuleGenerator());
generators.add(serviceRulesFactory.getLldpPostIngressVxlanRuleGenerator());
generators.add(serviceRulesFactory.getLldpPostIngressOneSwitchRuleGenerator());
generators.add(serviceRulesFactory.getArpPostIngressRuleGenerator());
generators.add(serviceRulesFactory.getArpPostIngressVxlanRuleGenerator());
generators.add(serviceRulesFactory.getArpPostIngressOneSwitchRuleGenerator());
if (switchProperties.isSwitchLldp()) {
generators.add(serviceRulesFactory.getLldpTransitRuleGenerator());
generators.add(serviceRulesFactory.getLldpInputPreDropRuleGenerator());
generators.add(serviceRulesFactory.getLldpIngressRuleGenerator());
}
if (switchProperties.isSwitchArp()) {
generators.add(serviceRulesFactory.getArpTransitRuleGenerator());
generators.add(serviceRulesFactory.getArpInputPreDropRuleGenerator());
generators.add(serviceRulesFactory.getArpIngressRuleGenerator());
}
Set<Integer> islPorts = adapter.getSwitchIslPorts(switchId);
islPorts.forEach(islPort -> {
generators.add(serviceRulesFactory.getEgressIslVxlanRuleGenerator(islPort));
generators.add(serviceRulesFactory.getEgressIslVlanRuleGenerator(islPort));
generators.add(serviceRulesFactory.getTransitIslVxlanRuleGenerator(islPort));
});
}
Integer server42Port = switchProperties.getServer42Port();
Integer server42Vlan = switchProperties.getServer42Vlan();
MacAddress server42MacAddress = switchProperties.getServer42MacAddress();
KildaFeatureToggles featureToggles = adapter.getFeatureToggles();
if (featureToggles.getServer42FlowRtt()) {
generators.add(serviceRulesFactory.getServer42FlowRttTurningRuleGenerator());
generators.add(serviceRulesFactory.getServer42FlowRttVxlanTurningRuleGenerator());
if (switchProperties.isServer42FlowRtt()) {
generators.add(serviceRulesFactory.getServer42FlowRttOutputVlanRuleGenerator(server42Port, server42Vlan, server42MacAddress));
generators.add(serviceRulesFactory.getServer42FlowRttOutputVxlanRuleGenerator(server42Port, server42Vlan, server42MacAddress));
}
}
if (featureToggles.getServer42IslRtt() && switchProperties.hasServer42IslRttEnabled()) {
generators.add(serviceRulesFactory.getServer42IslRttTurningRuleGenerator());
generators.add(serviceRulesFactory.getServer42IslRttOutputRuleGenerator(server42Port, server42Vlan, server42MacAddress));
for (Integer islPort : adapter.getSwitchIslPorts(switchId)) {
generators.add(serviceRulesFactory.getServer42IslRttInputRuleGenerator(server42Port, islPort));
}
}
return generators;
}
use of org.openkilda.model.MacAddress in project open-kilda by telstra.
the class UtilsTest method assertPushVxlan.
private void assertPushVxlan(ActionType actionType, PushVxlanAction pushVxlanAction) {
assertEquals(actionType, pushVxlanAction.getType());
assertEquals(new MacAddress(SWITCH_ID_1.toMacAddress()), pushVxlanAction.getSrcMacAddress());
assertEquals(new MacAddress(SWITCH_ID_2.toMacAddress()), pushVxlanAction.getDstMacAddress());
assertEquals(Constants.VXLAN_SRC_IPV4_ADDRESS, pushVxlanAction.getSrcIpv4Address());
assertEquals(Constants.VXLAN_DST_IPV4_ADDRESS, pushVxlanAction.getDstIpv4Address());
assertEquals(Constants.VXLAN_UDP_SRC, pushVxlanAction.getUdpSrc());
assertEquals(VNI, pushVxlanAction.getVni());
}
use of org.openkilda.model.MacAddress in project open-kilda by telstra.
the class Server42IslRttTurningRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
Set<FieldMatch> match = buildMatch(new MacAddress(config.getServer42IslRttMagicMacAddress()));
List<Action> actions = new ArrayList<>();
actions.add(SetFieldAction.builder().field(UDP_SRC).value(SERVER_42_ISL_RTT_REVERSE_UDP_PORT).build());
actions.add(new PortOutAction(new PortNumber(SpecialPortType.IN_PORT)));
Instructions instructions = Instructions.builder().applyActions(actions).build();
return Collections.singletonList(FlowSpeakerData.builder().switchId(sw.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(new Cookie(SERVER_42_ISL_RTT_TURNING_COOKIE)).table(OfTable.INPUT).priority(SERVER_42_ISL_RTT_TURNING_PRIORITY).match(match).instructions(instructions).build());
}
use of org.openkilda.model.MacAddress in project open-kilda by telstra.
the class Server42IslRttOutputRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
List<Action> actions = new ArrayList<>();
if (server42Vlan > 0) {
actions.add(new PushVlanAction());
actions.add(SetFieldAction.builder().field(Field.VLAN_VID).value(server42Vlan).build());
}
actions.add(SetFieldAction.builder().field(ETH_SRC).value(sw.getSwitchId().toMacAddressAsLong()).build());
actions.add(SetFieldAction.builder().field(ETH_DST).value(server42MacAddress.toLong()).build());
actions.add(new PortOutAction(new PortNumber(server42Port)));
Instructions instructions = Instructions.builder().applyActions(actions).build();
Set<FieldMatch> match = buildMatch(new MacAddress(config.getServer42IslRttMagicMacAddress()));
return Collections.singletonList(FlowSpeakerData.builder().switchId(sw.getSwitchId()).ofVersion(OfVersion.of(sw.getOfVersion())).cookie(new Cookie(SERVER_42_ISL_RTT_OUTPUT_COOKIE)).table(OfTable.INPUT).priority(SERVER_42_ISL_RTT_OUTPUT_PRIORITY).match(match).instructions(instructions).build());
}
use of org.openkilda.model.MacAddress in project open-kilda by telstra.
the class RecordHandler method doDeleteSwitchRules.
private void doDeleteSwitchRules(final CommandMessage message) {
SwitchRulesDeleteRequest request = (SwitchRulesDeleteRequest) message.getData();
logger.info("Deleting rules from '{}' switch: action={}, criteria={}", request.getSwitchId(), request.getDeleteRulesAction(), request.getCriteria());
final IKafkaProducerService producerService = getKafkaProducer();
final String replyToTopic = context.getKafkaSwitchManagerTopic();
DatapathId dpid = DatapathId.of(request.getSwitchId().toLong());
DeleteRulesAction deleteAction = request.getDeleteRulesAction();
DeleteRulesCriteria criteria = request.getCriteria();
ISwitchManager switchManager = context.getSwitchManager();
try {
List<Long> removedRules = new ArrayList<>();
if (deleteAction != null) {
switch(deleteAction) {
case REMOVE_DROP:
criteria = DeleteRulesCriteria.builder().cookie(DROP_RULE_COOKIE).build();
break;
case REMOVE_BROADCAST:
criteria = DeleteRulesCriteria.builder().cookie(VERIFICATION_BROADCAST_RULE_COOKIE).build();
break;
case REMOVE_UNICAST:
criteria = DeleteRulesCriteria.builder().cookie(VERIFICATION_UNICAST_RULE_COOKIE).build();
break;
case REMOVE_VERIFICATION_LOOP:
criteria = DeleteRulesCriteria.builder().cookie(DROP_VERIFICATION_LOOP_RULE_COOKIE).build();
break;
case REMOVE_BFD_CATCH:
criteria = DeleteRulesCriteria.builder().cookie(CATCH_BFD_RULE_COOKIE).build();
break;
case REMOVE_ROUND_TRIP_LATENCY:
criteria = DeleteRulesCriteria.builder().cookie(ROUND_TRIP_LATENCY_RULE_COOKIE).build();
break;
case REMOVE_UNICAST_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(VERIFICATION_UNICAST_VXLAN_RULE_COOKIE).build();
break;
case REMOVE_MULTITABLE_PRE_INGRESS_PASS_THROUGH:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE).build();
break;
case REMOVE_MULTITABLE_INGRESS_DROP:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_INGRESS_DROP_COOKIE).build();
break;
case REMOVE_MULTITABLE_POST_INGRESS_DROP:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_POST_INGRESS_DROP_COOKIE).build();
break;
case REMOVE_MULTITABLE_EGRESS_PASS_THROUGH:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_EGRESS_PASS_THROUGH_COOKIE).build();
break;
case REMOVE_MULTITABLE_TRANSIT_DROP:
criteria = DeleteRulesCriteria.builder().cookie(MULTITABLE_TRANSIT_DROP_COOKIE).build();
break;
case REMOVE_LLDP_INPUT_PRE_DROP:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_INPUT_PRE_DROP_COOKIE).build();
break;
case REMOVE_LLDP_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_INGRESS_COOKIE).build();
break;
case REMOVE_LLDP_POST_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_POST_INGRESS_COOKIE).build();
break;
case REMOVE_LLDP_POST_INGRESS_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_POST_INGRESS_VXLAN_COOKIE).build();
break;
case REMOVE_LLDP_POST_INGRESS_ONE_SWITCH:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_POST_INGRESS_ONE_SWITCH_COOKIE).build();
break;
case REMOVE_LLDP_TRANSIT:
criteria = DeleteRulesCriteria.builder().cookie(LLDP_TRANSIT_COOKIE).build();
break;
case REMOVE_ARP_INPUT_PRE_DROP:
criteria = DeleteRulesCriteria.builder().cookie(ARP_INPUT_PRE_DROP_COOKIE).build();
break;
case REMOVE_ARP_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(ARP_INGRESS_COOKIE).build();
break;
case REMOVE_ARP_POST_INGRESS:
criteria = DeleteRulesCriteria.builder().cookie(ARP_POST_INGRESS_COOKIE).build();
break;
case REMOVE_ARP_POST_INGRESS_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(ARP_POST_INGRESS_VXLAN_COOKIE).build();
break;
case REMOVE_ARP_POST_INGRESS_ONE_SWITCH:
criteria = DeleteRulesCriteria.builder().cookie(ARP_POST_INGRESS_ONE_SWITCH_COOKIE).build();
break;
case REMOVE_ARP_TRANSIT:
criteria = DeleteRulesCriteria.builder().cookie(ARP_TRANSIT_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_TURNING:
case REMOVE_SERVER_42_TURNING:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_TURNING_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_VXLAN_TURNING:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_VXLAN_TURNING_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_OUTPUT_VLAN:
case REMOVE_SERVER_42_OUTPUT_VLAN:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_OUTPUT_VLAN_COOKIE).build();
break;
case REMOVE_SERVER_42_FLOW_RTT_OUTPUT_VXLAN:
case REMOVE_SERVER_42_OUTPUT_VXLAN:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_FLOW_RTT_OUTPUT_VXLAN_COOKIE).build();
break;
case REMOVE_SERVER_42_ISL_RTT_TURNING:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_ISL_RTT_TURNING_COOKIE).build();
break;
case REMOVE_SERVER_42_ISL_RTT_OUTPUT:
criteria = DeleteRulesCriteria.builder().cookie(SERVER_42_ISL_RTT_OUTPUT_COOKIE).build();
break;
default:
logger.warn("Received unexpected delete switch rule action: {}", deleteAction);
}
// The cases when we delete all non-default rules.
if (deleteAction.nonDefaultRulesToBeRemoved()) {
removedRules.addAll(switchManager.deleteAllNonDefaultRules(dpid));
}
// The cases when we delete the default rules.
if (deleteAction.defaultRulesToBeRemoved()) {
removedRules.addAll(switchManager.deleteDefaultRules(dpid, request.getIslPorts(), request.getFlowPorts(), request.getFlowLldpPorts(), request.getFlowArpPorts(), request.getServer42FlowRttPorts(), request.isMultiTable(), request.isSwitchLldp(), request.isSwitchArp(), request.isServer42FlowRttFeatureToggle() && request.isServer42FlowRttSwitchProperty(), request.isServer42IslRttEnabled()));
}
}
// The case when we either delete by criteria or a specific default rule.
if (criteria != null) {
removedRules.addAll(switchManager.deleteRulesByCriteria(dpid, false, null, criteria));
}
// The cases when we (re)install the default rules.
if (deleteAction != null && deleteAction.defaultRulesToBeInstalled()) {
switchManager.installDefaultRules(dpid);
if (request.isMultiTable()) {
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_INGRESS_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_POST_INGRESS_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_EGRESS_PASS_THROUGH_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), MULTITABLE_TRANSIT_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_VXLAN_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_POST_INGRESS_ONE_SWITCH_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_VXLAN_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_POST_INGRESS_ONE_SWITCH_COOKIE);
for (int port : request.getIslPorts()) {
switchManager.installMultitableEndpointIslRules(dpid, port);
}
for (int port : request.getFlowPorts()) {
switchManager.installIntermediateIngressRule(dpid, port);
}
for (Integer port : request.getFlowLldpPorts()) {
switchManager.installLldpInputCustomerFlow(dpid, port);
}
for (Integer port : request.getFlowArpPorts()) {
switchManager.installArpInputCustomerFlow(dpid, port);
}
if (request.isSwitchLldp()) {
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INPUT_PRE_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_TRANSIT_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), LLDP_INGRESS_COOKIE);
}
if (request.isSwitchArp()) {
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INPUT_PRE_DROP_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_TRANSIT_COOKIE);
processInstallDefaultFlowByCookie(request.getSwitchId(), ARP_INGRESS_COOKIE);
}
}
Integer server42Port = request.getServer42Port();
Integer server42Vlan = request.getServer42Vlan();
MacAddress server42MacAddress = request.getServer42MacAddress();
if (request.isServer42FlowRttFeatureToggle()) {
switchManager.installServer42FlowRttTurningFlow(dpid);
switchManager.installServer42FlowRttVxlanTurningFlow(dpid);
if (request.isServer42FlowRttSwitchProperty() && server42Port != null && server42Vlan != null && server42MacAddress != null) {
switchManager.installServer42FlowRttOutputVlanFlow(dpid, server42Port, server42Vlan, server42MacAddress);
switchManager.installServer42FlowRttOutputVxlanFlow(dpid, server42Port, server42Vlan, server42MacAddress);
for (Integer port : request.getServer42FlowRttPorts()) {
switchManager.installServer42FlowRttInputFlow(dpid, server42Port, port, server42MacAddress);
}
}
}
if (request.isServer42IslRttEnabled()) {
switchManager.installServer42IslRttTurningFlow(dpid);
switchManager.installServer42IslRttOutputFlow(dpid, server42Port, server42Vlan, server42MacAddress);
for (Integer port : request.getIslPorts()) {
switchManager.installServer42IslRttInputFlow(dpid, server42Port, port);
}
}
}
SwitchRulesResponse response = new SwitchRulesResponse(removedRules);
InfoMessage infoMessage = new InfoMessage(response, System.currentTimeMillis(), message.getCorrelationId());
producerService.sendMessageAndTrack(replyToTopic, record.key(), infoMessage);
} catch (SwitchNotFoundException e) {
logger.error("Deleting switch rules was unsuccessful. Switch '{}' not found", request.getSwitchId());
anError(ErrorType.NOT_FOUND).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).withKey(record.key()).sendVia(producerService);
} catch (SwitchOperationException e) {
logger.error("Failed to delete switch '{}' rules.", request.getSwitchId(), e);
anError(ErrorType.DELETION_FAILURE).withMessage(e.getMessage()).withDescription(request.getSwitchId().toString()).withCorrelationId(message.getCorrelationId()).withTopic(replyToTopic).withKey(record.key()).sendVia(producerService);
}
}
Aggregations