use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class ExternalPeerRouterListCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService service = get(OpenstackNetworkService.class);
List<ExternalPeerRouter> routers = Lists.newArrayList(service.externalPeerRouters());
if (outputJson()) {
print("%s", json(this, routers));
} else {
print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
for (ExternalPeerRouter router : routers) {
print(FORMAT, router.ipAddress(), router.macAddress().toString(), router.vlanId());
}
}
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method processSnatPacket.
private void processSnatPacket(PacketContext context, Ethernet eth) {
if (getStatefulSnatFlag()) {
return;
}
IPv4 iPacket = (IPv4) eth.getPayload();
InboundPacket packetIn = context.inPacket();
int patPort = getPortNum();
InstancePort srcInstPort = instancePortService.instancePort(eth.getSourceMAC());
if (srcInstPort == null) {
log.error(ERR_PACKET_IN + "source host(MAC:{}) does not exist", eth.getSourceMAC());
return;
}
IpAddress srcIp = IpAddress.valueOf(iPacket.getSourceAddress());
Subnet srcSubnet = getSourceSubnet(srcInstPort, srcIp);
Router osRouter = getRouterFromSubnet(srcSubnet, osRouterService);
if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
// this router does not have external connectivity
log.warn("No router is associated with the given subnet {}", srcSubnet);
return;
}
IpAddress externalGatewayIp = externalGatewayIpSnatEnabled(osRouter, osNetworkAdminService);
if (externalGatewayIp == null) {
return;
}
ExternalPeerRouter externalPeerRouter = externalPeerRouterFromSubnet(srcSubnet, osRouterService, osNetworkService);
if (externalPeerRouter == null) {
return;
}
populateSnatFlowRules(context.inPacket(), srcInstPort, TpPort.tpPort(patPort), externalGatewayIp, externalPeerRouter);
packetOut(eth.duplicate(), packetIn.receivedFrom().deviceId(), patPort, externalGatewayIp, externalPeerRouter);
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter 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.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackNetworkManager method externalPeerRouterMac.
@Override
public MacAddress externalPeerRouterMac(ExternalGateway externalGateway) {
IpAddress ipAddress = getExternalPeerRouterIp(externalGateway);
if (ipAddress == null) {
return null;
}
ExternalPeerRouter peerRouter = osNetworkStore.externalPeerRouter(ipAddress.toString());
if (peerRouter == null) {
throw new NoSuchElementException();
} else {
return peerRouter.macAddress();
}
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackNetworkManager method deriveExternalPeerRouterMac.
@Override
public void deriveExternalPeerRouterMac(ExternalGateway externalGateway, Router router, VlanId vlanId) {
log.info("deriveExternalPeerRouterMac called");
IpAddress sourceIp = getExternalGatewaySourceIp(externalGateway, router);
IpAddress targetIp = getExternalPeerRouterIp(externalGateway);
if (sourceIp == null || targetIp == null) {
log.warn("Failed to derive external router mac address because " + "source IP {} or target IP {} is null", sourceIp, targetIp);
return;
}
ExternalPeerRouter peerRouter = osNetworkStore.externalPeerRouter(targetIp.toString());
// MAC address has been derived
if (peerRouter != null && !peerRouter.macAddress().equals(MacAddress.NONE)) {
return;
}
MacAddress sourceMac = Constants.DEFAULT_GATEWAY_MAC;
Ethernet ethRequest = ARP.buildArpRequest(sourceMac.toBytes(), sourceIp.toOctets(), targetIp.toOctets(), vlanId.id());
if (osNodeService.completeNodes(GATEWAY).isEmpty()) {
log.warn("There's no complete gateway");
return;
}
OpenstackNode gatewayNode = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
if (gatewayNode == null) {
return;
}
if (gatewayNode.uplinkPortNum() == null) {
log.warn("There's no uplink port for gateway node {}", gatewayNode.toString());
return;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(gatewayNode.uplinkPortNum()).build();
packetService.emit(new DefaultOutboundPacket(gatewayNode.intgBridge(), treatment, ByteBuffer.wrap(ethRequest.serialize())));
ExternalPeerRouter derivedRouter = DefaultExternalPeerRouter.builder().ipAddress(targetIp).macAddress(MacAddress.NONE).vlanId(vlanId).build();
osNetworkStore.createExternalPeerRouter(derivedRouter);
log.info("Initializes external peer router map with peer router IP {}", targetIp.toString());
}
Aggregations