use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method setComputeNodeToGatewayHelper.
// a helper method
private void setComputeNodeToGatewayHelper(InstancePort instPort, Network osNet, Set<OpenstackNode> gateways, boolean install) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(instPort.ipAddress().toIpPrefix()).matchEthDst(Constants.DEFAULT_GATEWAY_MAC);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
OpenstackNode selectedGatewayNode = getGwByComputeDevId(gateways, instPort.deviceId());
if (selectedGatewayNode == null) {
log.warn(ERR_FLOW + "no gateway node selected");
return;
}
Type netType = osNetworkService.networkType(osNet.getId());
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, osNodeService.node(instPort.deviceId()));
if (portNum == null) {
log.warn(ERR_FLOW + "no tunnel port");
return;
}
sBuilder.matchTunnelId(Long.parseLong(osNet.getProviderSegID()));
tBuilder.extension(buildExtension(deviceService, instPort.deviceId(), selectedGatewayNode.dataIp().getIp4Address()), instPort.deviceId()).setOutput(portNum);
break;
case VLAN:
if (osNodeService.node(instPort.deviceId()).vlanPortNum() == null) {
log.warn(ERR_FLOW + "no vlan port");
return;
}
sBuilder.matchVlanId(VlanId.vlanId(osNet.getProviderSegID()));
tBuilder.setOutput(osNodeService.node(instPort.deviceId()).vlanPortNum());
break;
default:
log.warn(ERR_FLOW + "no supported network type");
}
osFlowRuleService.setRule(appId, instPort.deviceId(), sBuilder.build(), tBuilder.build(), PRIORITY_EXTERNAL_FLOATING_ROUTING_RULE, ROUTING_TABLE, install);
log.trace("Succeeded to set flow rules from compute node to gateway on compute node");
}
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);
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setSourceNat.
private void setSourceNat(RouterInterface routerIface, boolean install) {
Subnet osSubnet = osNetworkAdminService.subnet(routerIface.getSubnetId());
Network osNet = osNetworkAdminService.network(osSubnet.getNetworkId());
Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
osNodeService.completeNodes(COMPUTE).forEach(cNode -> {
setRulesToGateway(cNode, osNet.getProviderSegID(), IpPrefix.valueOf(osSubnet.getCidr()), netType, install);
});
if (getStatefulSnatFlag()) {
setStatefulSnatRules(routerIface, install);
} else {
setReactiveSnatRules(routerIface, install);
}
final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
log.info(updateStr + "external access for subnet({})", osSubnet.getCidr());
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setArpRequestRule.
/**
* Installs flow rules to match ARP request packets.
*
* @param port instance port
* @param install installation flag
*/
private void setArpRequestRule(InstancePort port, boolean install) {
Type netType = osNetworkService.networkType(port.networkId());
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
setRemoteArpRequestRuleForTunnel(port, install);
setLocalArpRequestRuleForVnet(port, install);
break;
case VLAN:
setArpRequestRuleForVlan(port, install);
setLocalArpRequestRuleForVnet(port, install);
break;
default:
break;
}
}
Aggregations