use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setStatefulSnatRules.
private void setStatefulSnatRules(RouterInterface routerIface, boolean install) {
Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
if (netType == FLAT) {
log.warn("FLAT typed network does not need SNAT rules");
return;
}
Optional<Router> osRouter = osRouterService.routers().stream().filter(router -> routerIface.getId().equals(router.getId())).findAny();
if (!osRouter.isPresent()) {
log.warn("Cannot find a router attached with the given router interface {} ", routerIface);
return;
}
IpAddress natAddress = externalGatewayIpSnatEnabled(osRouter.get(), osNetworkAdminService);
if (natAddress == null) {
log.debug("NAT address is not found");
return;
}
IpAddress extRouterAddress = getGatewayIpAddress(osRouter.get());
if (extRouterAddress == null) {
log.warn("External router address is not found");
return;
}
ExternalPeerRouter externalPeerRouter = osNetworkService.externalPeerRouter(extRouterAddress);
if (externalPeerRouter == null) {
log.warn("External peer router not found");
return;
}
Map<OpenstackNode, PortRange> gwPortRangeMap = getAssignedPortsForGateway(ImmutableList.copyOf(osNodeService.nodes(GATEWAY)));
osNodeService.completeNodes(GATEWAY).forEach(gwNode -> {
if (install) {
PortRange gwPortRange = gwPortRangeMap.get(gwNode);
Map<String, PortRange> netPortRangeMap = getAssignedPortsForNet(getNetIdByRouterId(routerIface.getId()), gwPortRange.min(), gwPortRange.max());
PortRange netPortRange = netPortRangeMap.get(osNet.getId());
setStatefulSnatUpstreamRule(gwNode, natAddress, Long.parseLong(osNet.getProviderSegID()), externalPeerRouter, netPortRange.min(), netPortRange.max(), install);
} else {
setStatefulSnatUpstreamRule(gwNode, natAddress, Long.parseLong(osNet.getProviderSegID()), externalPeerRouter, 0, 0, install);
}
});
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setStatelessSnatDownstreamRules.
private void setStatelessSnatDownstreamRules(InstancePort srcInstPort, String segmentId, Type networkType, IpAddress externalIp, ExternalPeerRouter externalPeerRouter, TpPort patPort, InboundPacket packetIn) {
IPv4 iPacket = (IPv4) packetIn.parsed().getPayload();
IpAddress internalIp = IpAddress.valueOf(iPacket.getSourceAddress());
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPProtocol(iPacket.getProtocol()).matchIPDst(IpPrefix.valueOf(externalIp.getIp4Address(), VM_PREFIX)).matchIPSrc(IpPrefix.valueOf(iPacket.getDestinationAddress(), VM_PREFIX));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setEthDst(packetIn.parsed().getSourceMAC()).setIpDst(internalIp);
if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
sBuilder.matchVlanId(externalPeerRouter.vlanId());
tBuilder.popVlan();
}
switch(networkType) {
case VXLAN:
case GRE:
case GENEVE:
tBuilder.setTunnelId(Long.parseLong(segmentId));
break;
case VLAN:
tBuilder.pushVlan().setVlanId(VlanId.vlanId(segmentId));
break;
default:
final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
throw new IllegalStateException(error);
}
switch(iPacket.getProtocol()) {
case IPv4.PROTOCOL_TCP:
TCP tcpPacket = (TCP) iPacket.getPayload();
sBuilder.matchTcpSrc(TpPort.tpPort(tcpPacket.getDestinationPort())).matchTcpDst(patPort);
tBuilder.setTcpDst(TpPort.tpPort(tcpPacket.getSourcePort()));
break;
case IPv4.PROTOCOL_UDP:
UDP udpPacket = (UDP) iPacket.getPayload();
sBuilder.matchUdpSrc(TpPort.tpPort(udpPacket.getDestinationPort())).matchUdpDst(patPort);
tBuilder.setUdpDst(TpPort.tpPort(udpPacket.getSourcePort()));
break;
default:
break;
}
OpenstackNode srcNode = osNodeService.node(srcInstPort.deviceId());
osNodeService.completeNodes(GATEWAY).forEach(gNode -> {
TrafficTreatment treatment = getDownstreamTreatment(networkType, tBuilder, gNode, srcNode);
osFlowRuleService.setRule(appId, gNode.intgBridge(), sBuilder.build(), treatment, PRIORITY_SNAT_RULE, GW_COMMON_TABLE, true);
});
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setRulesToGateway.
private void setRulesToGateway(OpenstackNode osNode, String segmentId, IpPrefix srcSubnet, Type networkType, boolean install) {
OpenstackNode sourceNatGateway = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
if (sourceNatGateway == null) {
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcSubnet.getIp4Prefix()).matchEthDst(Constants.DEFAULT_GATEWAY_MAC);
switch(networkType) {
case VXLAN:
case GRE:
case GENEVE:
sBuilder.matchTunnelId(Long.parseLong(segmentId));
break;
case VLAN:
sBuilder.matchVlanId(VlanId.vlanId(segmentId));
break;
default:
final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
throw new IllegalStateException(error);
}
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
switch(networkType) {
case VXLAN:
case GRE:
case GENEVE:
PortNumber portNum = tunnelPortNumByNetType(networkType, osNode);
tBuilder.extension(buildExtension(deviceService, osNode.intgBridge(), sourceNatGateway.dataIp().getIp4Address()), osNode.intgBridge()).setOutput(portNum);
break;
case VLAN:
tBuilder.setOutput(osNode.vlanPortNum());
break;
default:
break;
}
osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_EXTERNAL_ROUTING_RULE, ROUTING_TABLE, install);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setArpReplyRuleForGeneve.
/**
* Installs flow rules to match ARP reply packets only for GENEVE.
*
* @param port instance port
* @param install installation flag
*/
private void setArpReplyRuleForGeneve(InstancePort port, boolean install) {
OpenstackNode localNode = osNodeService.node(port.deviceId());
TrafficSelector selector = getArpReplySelectorForGeneve(port);
setLocalArpReplyTreatmentForGeneve(selector, port, install);
setRemoteArpTreatmentForTunnel(selector, port, localNode, install);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setRemoteArpTreatmentForVlan.
// a helper method
private void setRemoteArpTreatmentForVlan(TrafficSelector selector, InstancePort port, short arpOp, boolean install) {
int priority;
if (arpOp == ARP.OP_REQUEST) {
priority = PRIORITY_ARP_REQUEST_RULE;
} else if (arpOp == ARP.OP_REPLY) {
priority = PRIORITY_ARP_REPLY_RULE;
} else {
// if ARP op does not match with any operation mode, we simply
// configure the ARP request rule priority
priority = PRIORITY_ARP_REQUEST_RULE;
}
for (OpenstackNode remoteNode : osNodeService.completeNodes(COMPUTE)) {
if (!remoteNode.intgBridge().equals(port.deviceId()) && remoteNode.vlanIntf() != null) {
TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().setOutput(remoteNode.vlanPortNum()).build();
osFlowRuleService.setRule(appId, remoteNode.intgBridge(), selector, treatmentToRemote, priority, ARP_TABLE, install);
}
}
}
Aggregations