use of org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GATEWAY_RULE in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setFakeGatewayArpRule.
/**
* Installs flow rules which convert ARP request packet into ARP reply
* by adding a fake gateway MAC address as Source Hardware Address.
*
* @param osSubnet openstack subnet
* @param network openstack network
* @param install flag which indicates whether to install rule or remove rule
* @param osNode openstack node
*/
private void setFakeGatewayArpRule(Subnet osSubnet, Network network, boolean install, OpenstackNode osNode) {
if (ARP_BROADCAST_MODE.equals(getArpMode())) {
Type netType = osNetworkService.networkType(network.getId());
String gateway = osSubnet.getGateway();
if (gateway == null) {
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
if (netType == VLAN) {
sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
} else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
// different networks
if (!install) {
long numOfDupGws = osNetworkService.subnets().stream().filter(s -> !s.getId().equals(osSubnet.getId())).filter(s -> s.getGateway() != null).filter(s -> s.getGateway().equals(osSubnet.getGateway())).count();
if (numOfDupGws > 0) {
return;
}
}
}
sBuilder.matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(gateway));
if (osNode == null) {
osNodeService.completeNodes(COMPUTE).forEach(n -> {
Device device = deviceService.getDevice(n.intgBridge());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (netType == VLAN) {
tBuilder.popVlan();
}
tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setEthSrc(MacAddress.valueOf(gatewayMac)).setOutput(PortNumber.IN_PORT);
osFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
});
} else {
Device device = deviceService.getDevice(osNode.intgBridge());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (netType == VLAN) {
tBuilder.popVlan();
}
tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setOutput(PortNumber.IN_PORT);
osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
}
}
}
Aggregations