use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY 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.openstacknode.api.OpenstackNode.NodeType.GATEWAY 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.openstacknode.api.OpenstackNode.NodeType.GATEWAY in project onos by opennetworkinglab.
the class OpenstackRoutingArpHandler method processArpPacket.
private void processArpPacket(PacketContext context, Ethernet ethernet) {
ARP arp = (ARP) ethernet.getPayload();
if (arp.getOpCode() == ARP.OP_REQUEST && ARP_PROXY_MODE.equals(getArpMode())) {
if (log.isTraceEnabled()) {
log.trace("ARP request received from {} for {}", Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(), Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString());
}
IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress());
MacAddress targetMac = null;
NetFloatingIP floatingIP = osRouterAdminService.floatingIps().stream().filter(ip -> ip.getFloatingIpAddress().equals(targetIp.toString())).findAny().orElse(null);
// In case target ip is for associated floating ip, sets target mac to vm's.
if (floatingIP != null && floatingIP.getPortId() != null) {
InstancePort instPort = instancePortService.instancePort(floatingIP.getPortId());
if (instPort == null) {
log.trace("Unknown target ARP request for {}, ignore it", targetIp);
return;
} else {
targetMac = instPort.macAddress();
}
OpenstackNode gw = getGwByInstancePort(osNodeService.completeNodes(GATEWAY), instPort);
if (gw == null) {
return;
}
// if the ARP packet_in received from non-relevant GWs, we simply ignore it
if (!Objects.equals(gw.intgBridge(), context.inPacket().receivedFrom().deviceId())) {
return;
}
}
if (isExternalGatewaySourceIp(targetIp)) {
targetMac = Constants.DEFAULT_GATEWAY_MAC;
}
if (targetMac == null) {
log.trace("Unknown target ARP request for {}, ignore it", targetIp);
return;
}
Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), targetMac, ethernet);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(context.inPacket().receivedFrom().port()).build();
packetService.emit(new DefaultOutboundPacket(context.inPacket().receivedFrom().deviceId(), treatment, ByteBuffer.wrap(ethReply.serialize())));
context.block();
}
if (arp.getOpCode() == ARP.OP_REPLY) {
ConnectPoint cp = context.inPacket().receivedFrom();
PortNumber receivedPortNum = cp.port();
IpAddress spa = Ip4Address.valueOf(arp.getSenderProtocolAddress());
MacAddress sha = MacAddress.valueOf(arp.getSenderHardwareAddress());
log.debug("ARP reply ip: {}, mac: {}", spa, sha);
try {
Set<String> extRouterIps = osNetworkService.externalPeerRouters().stream().map(r -> r.ipAddress().toString()).collect(Collectors.toSet());
// if SPA is NOT contained in existing external router IP set, we ignore it
if (!extRouterIps.contains(spa.toString())) {
return;
}
OpenstackNode node = osNodeService.node(cp.deviceId());
if (node == null) {
return;
}
// we only handles the ARP-Reply message received by gateway node
if (node.type() != GATEWAY) {
return;
}
if (receivedPortNum.equals(node.uplinkPortNum())) {
osNetworkAdminService.updateExternalPeerRouterMac(spa, sha);
}
} catch (Exception e) {
log.error("Exception occurred because of {}", e);
}
}
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY in project onos by opennetworkinglab.
the class OpenstackNorthSouthProbeCommand method doExecute.
@Override
protected void doExecute() {
OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
InstancePortService instPortService = get(InstancePortService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
MastershipService mastershipService = get(MastershipService.class);
ClusterService clusterService = get(ClusterService.class);
if (tsService == null || osNodeService == null || instPortService == null || mastershipService == null) {
error("Failed to troubleshoot openstack networking.");
return;
}
if ((!isAll && vmIps == null) || (isAll && vmIps != null)) {
print("Please specify one of VM IP address or -a option.");
return;
}
NodeId localNodeId = clusterService.getLocalNode().id();
for (OpenstackNode gw : osNodeService.completeNodes(GATEWAY)) {
if (!localNodeId.equals(mastershipService.getMasterFor(gw.intgBridge()))) {
error("Current node is not the master for all gateway nodes. " + "Please enforce mastership first using openstack-reset-mastership -c !");
return;
}
}
if (isAll) {
printHeader();
// send ICMP PACKET_OUT to all connect VMs whose instance port state is ACTIVE
instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).filter(p -> instPortService.floatingIp(p.portId()) != null).forEach(port -> printReachability(tsService.probeNorthSouth(port)));
} else {
final Set<InstancePort> ports = Sets.newConcurrentHashSet();
for (String ip : vmIps) {
instPortService.instancePorts().stream().filter(p -> p.state().equals(InstancePort.State.ACTIVE)).filter(p -> instPortService.floatingIp(p.portId()) != null).filter(p -> ip.equals(instPortService.floatingIp(p.portId()).toString())).forEach(ports::add);
}
printHeader();
ports.forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeNorthSouth(port))));
}
}
Aggregations