use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method setGatewayRules.
private void setGatewayRules(Subnet osSubnet, Router osRouter, boolean install) {
OpenstackNode srcNatGw = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
if (srcNatGw == null) {
return;
}
if (Strings.isNullOrEmpty(osSubnet.getGateway())) {
// do nothing if no gateway is set
return;
}
Network net = osNetworkAdminService.network(osSubnet.getNetworkId());
Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
Set<Subnet> routableSubnets = routableSubnets(osRouter, osSubnet.getId());
// install rules to each compute node for routing IP packets to gateways
osNodeService.completeNodes(COMPUTE).stream().filter(cNode -> cNode.dataIp() != null).forEach(cNode -> setRulesToGatewayWithRoutableSubnets(cNode, srcNatGw, net.getProviderSegID(), osSubnet, routableSubnets, netType, install));
// install rules to punt ICMP packets to controller at gateway node
// this rule is only valid for stateless ICMP SNAT case
osNodeService.completeNodes(GATEWAY).forEach(gNode -> setReactiveGatewayIcmpRule(IpAddress.valueOf(osSubnet.getGateway()), gNode.intgBridge(), install));
final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
log.debug(updateStr + "IP to {}", osSubnet.getGateway());
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method setRouterAdminRules.
private void setRouterAdminRules(String segmentId, Type networkType, boolean install) {
TrafficTreatment treatment;
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
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);
}
treatment = DefaultTrafficTreatment.builder().drop().build();
osNodeService.completeNodes().stream().filter(osNode -> osNode.type() == COMPUTE).forEach(osNode -> {
osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), treatment, PRIORITY_ADMIN_RULE, ROUTING_TABLE, install);
});
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method routerIfaceRemoved.
private void routerIfaceRemoved(Router osRouter, RouterInterface osRouterIface) {
Subnet osSubnet = osNetworkAdminService.subnet(osRouterIface.getSubnetId());
if (osSubnet == null) {
final String error = String.format("Failed to set flows for router %s: subnet %s does not exist", osRouterIface.getId(), osRouterIface.getSubnetId());
throw new IllegalStateException(error);
}
if (!osRouter.isAdminStateUp()) {
Network network = osNetworkAdminService.network(osSubnet.getNetworkId());
Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
setRouterAdminRules(network.getProviderSegID(), netType, false);
}
setInternalRoutes(osRouter, osSubnet, false);
setGatewayRules(osSubnet, osRouter, false);
log.info("Disconnected subnet({}) from {}", osSubnet.getCidr(), deriveResourceName(osRouter));
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method populateSnatFlowRules.
private void populateSnatFlowRules(InboundPacket packetIn, InstancePort srcInstPort, TpPort patPort, IpAddress externalIp, ExternalPeerRouter externalPeerRouter) {
Network osNet = osNetworkService.network(srcInstPort.networkId());
Type netType = osNetworkService.networkType(srcInstPort.networkId());
if (osNet == null) {
final String error = String.format("%s network %s not found", ERR_PACKET_IN, srcInstPort.networkId());
throw new IllegalStateException(error);
}
setStatelessSnatDownstreamRules(srcInstPort, osNet.getProviderSegID(), netType, externalIp, externalPeerRouter, patPort, packetIn);
setStatelessSnatUpstreamRules(osNet.getProviderSegID(), netType, externalIp, externalPeerRouter, patPort, packetIn);
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setGatewayToInstanceDownstreamRule.
private void setGatewayToInstanceDownstreamRule(OpenstackNode gwNode, InstancePort instPort, boolean install) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(instPort.ipAddress(), VM_PREFIX)).build();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setEthDst(instPort.macAddress());
Type netType = osNetworkAdminService.networkType(instPort.networkId());
String segId = osNetworkAdminService.segmentId(instPort.networkId());
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
tBuilder.setTunnelId(Long.valueOf(segId));
break;
case VLAN:
default:
final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, netType.name());
throw new IllegalStateException(error);
}
OpenstackNode srcNode = osNodeService.node(instPort.deviceId());
TrafficTreatment treatment = getDownstreamTreatment(netType, tBuilder, gwNode, srcNode);
osFlowRuleService.setRule(appId, gwNode.intgBridge(), selector, treatment, PRIORITY_STATEFUL_SNAT_RULE, GW_COMMON_TABLE, install);
}
Aggregations