use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method routerIfaceAdded.
private void routerIfaceAdded(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, true);
}
setInternalRoutes(osRouter, osSubnet, true);
setGatewayRules(osSubnet, osRouter, true);
log.info("Connected subnet({}) to {}", osSubnet.getCidr(), deriveResourceName(osRouter));
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method routerRemove.
private void routerRemove(Router osRouter) {
osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> {
Network network = osNetworkAdminService.network(osNetworkAdminService.subnet(iface.getSubnetId()).getNetworkId());
Type netType = osNetworkAdminService.networkType(osNetworkAdminService.subnet(iface.getSubnetId()).getNetworkId());
setRouterAdminRules(network.getProviderSegID(), netType, false);
});
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method setDownstreamExternalRulesHelper.
private void setDownstreamExternalRulesHelper(NetFloatingIP floatingIp, Network osNet, InstancePort instPort, ExternalPeerRouter externalPeerRouter, Set<OpenstackNode> gateways, boolean install) {
OpenstackNode cNode = osNodeService.node(instPort.deviceId());
Type netType = osNetworkService.networkType(osNet.getId());
if (cNode == null) {
final String error = String.format("Cannot find openstack node for device %s", instPort.deviceId());
throw new IllegalStateException(error);
}
if (netType == VXLAN && cNode.dataIp() == null) {
final String errorFormat = ERR_FLOW + "VXLAN mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
if (netType == GRE && cNode.dataIp() == null) {
final String errorFormat = ERR_FLOW + "GRE mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
if (netType == GENEVE && cNode.dataIp() == null) {
final String errorFormat = ERR_FLOW + "GENEVE mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
if (netType == VLAN && cNode.vlanIntf() == null) {
final String errorFormat = ERR_FLOW + "VLAN mode is not ready for %s";
final String error = String.format(errorFormat, floatingIp, cNode.hostname());
throw new IllegalStateException(error);
}
IpAddress floating = IpAddress.valueOf(floatingIp.getFloatingIpAddress());
OpenstackNode selectedGatewayNode = getGwByComputeDevId(gateways, instPort.deviceId());
if (selectedGatewayNode == null) {
final String errorFormat = ERR_FLOW + "no gateway node selected";
throw new IllegalStateException(errorFormat);
}
TrafficSelector.Builder externalSelectorBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(selectedGatewayNode.uplinkPortNum()).matchIPDst(floating.toIpPrefix());
TrafficTreatment.Builder externalTreatmentBuilder = DefaultTrafficTreatment.builder().setEthSrc(Constants.DEFAULT_GATEWAY_MAC).setEthDst(instPort.macAddress()).setIpDst(instPort.ipAddress().getIp4Address());
if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
externalSelectorBuilder.matchVlanId(externalPeerRouter.vlanId()).build();
externalTreatmentBuilder.popVlan();
}
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, selectedGatewayNode);
externalTreatmentBuilder.setTunnelId(Long.valueOf(osNet.getProviderSegID())).extension(buildExtension(deviceService, selectedGatewayNode.intgBridge(), cNode.dataIp().getIp4Address()), selectedGatewayNode.intgBridge()).setOutput(portNum);
break;
case VLAN:
externalTreatmentBuilder.pushVlan().setVlanId(VlanId.vlanId(osNet.getProviderSegID())).setOutput(selectedGatewayNode.vlanPortNum());
break;
default:
final String error = String.format(ERR_UNSUPPORTED_NET_TYPE, osNet.getNetworkType());
throw new IllegalStateException(error);
}
osFlowRuleService.setRule(appId, selectedGatewayNode.intgBridge(), externalSelectorBuilder.build(), externalTreatmentBuilder.build(), PRIORITY_FLOATING_EXTERNAL, GW_COMMON_TABLE, install);
setArpRule(floatingIp, instPort.macAddress(), selectedGatewayNode, install);
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method setUpstreamRules.
private void setUpstreamRules(NetFloatingIP floatingIp, Network osNet, InstancePort instPort, ExternalPeerRouter externalPeerRouter, boolean install) {
IpAddress floating = IpAddress.valueOf(floatingIp.getFloatingIpAddress());
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(instPort.ipAddress().toIpPrefix());
Type netType = osNetworkService.networkType(osNet.getId());
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
sBuilder.matchTunnelId(Long.valueOf(osNet.getProviderSegID()));
break;
case VLAN:
sBuilder.matchVlanId(VlanId.vlanId(osNet.getProviderSegID()));
break;
default:
final String error = String.format(ERR_UNSUPPORTED_NET_TYPE, osNet.getNetworkType());
throw new IllegalStateException(error);
}
TrafficSelector selector = sBuilder.build();
osNodeService.completeNodes(GATEWAY).forEach(gNode -> {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpSrc(floating.getIp4Address()).setEthSrc(instPort.macAddress()).setEthDst(externalPeerRouter.macAddress());
if (netType == VLAN) {
tBuilder.popVlan();
}
if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
tBuilder.pushVlan().setVlanId(externalPeerRouter.vlanId());
}
osFlowRuleService.setRule(appId, gNode.intgBridge(), selector, tBuilder.setOutput(gNode.uplinkPortNum()).build(), PRIORITY_FLOATING_EXTERNAL, GW_COMMON_TABLE, install);
});
log.trace("Succeeded to set flow rules for upstream on gateway nodes");
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setReactiveSnatRules.
private void setReactiveSnatRules(RouterInterface routerIface, boolean install) {
Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
osNodeService.completeNodes(GATEWAY).forEach(gwNode -> setRulesToController(gwNode.intgBridge(), osNet.getProviderSegID(), IpPrefix.valueOf(osSubnet.getCidr()), netType, install));
}
Aggregations