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 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 OpenstackNetworkingUiMessageHandler method traceRequestString.
private String traceRequestString(String srcIp, String dstIp, InstancePort srcInstancePort, OpenstackNetworkService osNetService, boolean uplink) {
StringBuilder requestStringBuilder = new StringBuilder(DEFAULT_REQUEST_STRING);
if (uplink) {
requestStringBuilder.append(COMMA).append(IN_PORT).append(srcInstancePort.portNumber().toString()).append(COMMA).append(NW_SRC).append(srcIp).append(COMMA);
Type netType = osNetService.networkType(srcInstancePort.networkId());
if (netType == VXLAN || netType == VLAN || netType == GRE || netType == GENEVE) {
if (srcIp.equals(dstIp)) {
dstIp = osNetService.gatewayIp(srcInstancePort.portId());
requestStringBuilder.append(DL_DST).append(DEFAULT_GATEWAY_MAC_STR).append(COMMA);
} else if (!osNetService.ipPrefix(srcInstancePort.portId()).contains(IpAddress.valueOf(dstIp))) {
requestStringBuilder.append(DL_DST).append(DEFAULT_GATEWAY_MAC_STR).append(COMMA);
}
} else {
if (srcIp.equals(dstIp)) {
dstIp = osNetService.gatewayIp(srcInstancePort.portId());
}
}
requestStringBuilder.append(NW_DST).append(dstIp).append("\n");
} else {
requestStringBuilder.append(COMMA).append(NW_SRC).append(dstIp).append(COMMA);
if (osNetService.networkType(srcInstancePort.networkId()).equals(VXLAN) || osNetService.networkType(srcInstancePort.networkId()).equals(VLAN)) {
requestStringBuilder.append(TUN_ID).append(osNetService.segmentId(srcInstancePort.networkId())).append(COMMA);
}
requestStringBuilder.append(NW_DST).append(srcIp).append("\n");
}
return requestStringBuilder.toString();
}
use of org.onosproject.openstacknetworking.api.OpenstackNetwork.Type 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.openstacknetworking.api.OpenstackNetwork.Type in project onos by opennetworkinglab.
the class OpenstackSecurityGroupHandler method buildTunnelId.
private void buildTunnelId(TrafficSelector.Builder sBuilder, String netId) {
String segId = osNetService.segmentId(netId);
Type netType = osNetService.networkType(netId);
if (netType == VLAN) {
sBuilder.matchVlanId(VlanId.vlanId(segId));
} else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
sBuilder.matchTunnelId(Long.valueOf(segId));
} else {
log.debug("Cannot tag the VID due to lack of support of virtual network type {}", netType);
}
}
Aggregations