use of org.projectfloodlight.openflow.types.DatapathId 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);
}
}
use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.
the class SwitchManager method removeFlowByOfFlowDelete.
private List<Long> removeFlowByOfFlowDelete(DatapathId dpid, int tableId, OFFlowDelete dropFlowDelete) throws SwitchOperationException {
List<OFFlowStatsEntry> flowStatsBefore = dumpFlowTable(dpid, tableId);
IOFSwitch sw = lookupSwitch(dpid);
pushFlow(sw, "--DeleteFlow--", dropFlowDelete);
// Wait for OFFlowDelete to be processed.
sendBarrierRequest(sw);
List<OFFlowStatsEntry> flowStatsAfter = dumpFlowTable(dpid, tableId);
Set<Long> cookiesAfter = flowStatsAfter.stream().map(entry -> entry.getCookie().getValue()).collect(toSet());
return flowStatsBefore.stream().map(entry -> entry.getCookie().getValue()).filter(cookie -> !cookiesAfter.contains(cookie)).peek(cookie -> logger.info("Rule with cookie {} has been removed from switch {}.", cookie, dpid)).collect(toList());
}
use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.
the class SwitchManager method buildExpectedServer42IslRttFlows.
@Override
public List<OFFlowMod> buildExpectedServer42IslRttFlows(DatapathId dpid, boolean server42IslRtt, Integer server42Port, Integer server42Vlan, org.openkilda.model.MacAddress server42MacAddress, Collection<Integer> islPorts) throws SwitchNotFoundException {
List<SwitchFlowGenerator> generators = new ArrayList<>();
if (server42IslRtt) {
generators.add(switchFlowFactory.getServer42IslRttTurningFlowGenerator());
generators.add(switchFlowFactory.getServer42IslRttOutputFlowGenerator(server42Port, server42Vlan, server42MacAddress));
for (Integer islPort : islPorts) {
generators.add(switchFlowFactory.getServer42IslRttInputFlowGenerator(server42Port, islPort));
}
}
IOFSwitch sw = lookupSwitch(dpid);
return generators.stream().map(g -> g.generateFlow(sw)).map(SwitchFlowTuple::getFlow).filter(Objects::nonNull).collect(toList());
}
use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.
the class SwitchManager method deleteRulesByCriteria.
@Override
public List<Long> deleteRulesByCriteria(DatapathId dpid, boolean multiTable, RuleType ruleType, DeleteRulesCriteria... criteria) throws SwitchOperationException {
List<OFFlowStatsEntry> flowStatsBefore = dumpFlowTable(dpid);
IOFSwitch sw = lookupSwitch(dpid);
OFFactory ofFactory = sw.getOFFactory();
for (DeleteRulesCriteria criteriaEntry : criteria) {
OFFlowDelete dropFlowDelete = buildFlowDeleteByCriteria(ofFactory, criteriaEntry, multiTable, ruleType);
logger.info("Rules by criteria {} are to be removed from switch {}.", criteria, dpid);
pushFlow(sw, "--DeleteFlow--", dropFlowDelete);
}
// Wait for OFFlowDelete to be processed.
sendBarrierRequest(sw);
List<OFFlowStatsEntry> flowStatsAfter = dumpFlowTable(dpid);
Set<Long> cookiesAfter = flowStatsAfter.stream().map(entry -> entry.getCookie().getValue()).collect(Collectors.toSet());
return flowStatsBefore.stream().map(entry -> entry.getCookie().getValue()).filter(cookie -> !cookiesAfter.contains(cookie)).peek(cookie -> logger.info("Rule with cookie {} has been removed from switch {}.", cookie, dpid)).collect(toList());
}
use of org.projectfloodlight.openflow.types.DatapathId in project open-kilda by telstra.
the class PingService method wrapData.
/**
* Wrap ping data into L2, l3 and L4 network packages.
*/
public IPacket wrapData(Ping ping, byte[] payload) throws PingImpossibleException {
Data l7 = new Data(payload);
UDP l4 = new UDP();
l4.setPayload(l7);
l4.setSourcePort(TransportPort.of(NET_L3_PORT));
l4.setDestinationPort(TransportPort.of(NET_L3_PORT));
IPv4 l3 = new IPv4();
l3.setPayload(l4);
l3.setSourceAddress(NET_L3_ADDRESS);
l3.setDestinationAddress(NET_L3_ADDRESS);
l3.setTtl(NET_L3_TTL);
Ethernet l2 = new Ethernet();
l2.setPayload(l3);
l2.setEtherType(EthType.IPv4);
l2.setSourceMACAddress(magicSourceMacAddress);
DatapathId egressSwitch = DatapathId.of(ping.getDest().getDatapath().toLong());
l2.setDestinationMACAddress(MacAddress.of(egressSwitch));
if (FlowEncapsulationType.TRANSIT_VLAN.equals(ping.getTransitEncapsulation().getType())) {
l2.setVlanID(ping.getTransitEncapsulation().getId().shortValue());
return l2;
} else if (FlowEncapsulationType.VXLAN.equals(ping.getTransitEncapsulation().getType())) {
Vxlan vxlan = new Vxlan();
vxlan.setPayload(l2);
vxlan.setVni(ping.getTransitEncapsulation().getId());
UDP udp = new UDP();
udp.setPayload(vxlan);
udp.setSourcePort(TransportPort.of(SwitchManager.STUB_VXLAN_UDP_SRC));
udp.setDestinationPort(TransportPort.of(SwitchManager.VXLAN_UDP_DST));
IPv4 ipv4 = new IPv4();
ipv4.setPayload(udp);
ipv4.setProtocol(IpProtocol.UDP);
ipv4.setSourceAddress(SwitchManager.STUB_VXLAN_IPV4_SRC);
ipv4.setDestinationAddress(SwitchManager.STUB_VXLAN_IPV4_DST);
ipv4.setTtl(NET_L3_TTL);
Ethernet ethernet = new Ethernet();
ethernet.setPayload(ipv4);
ethernet.setEtherType(EthType.IPv4);
ethernet.setSourceMACAddress(magicSourceMacAddress);
ethernet.setDestinationMACAddress(MacAddress.of(egressSwitch));
return ethernet;
}
throw new PingImpossibleException(ping, Errors.INCORRECT_REQUEST);
}
Aggregations