use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class UpdateExternalPeerRouterVlanCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkAdminService osNetAdminService = get(OpenstackNetworkAdminService.class);
OpenstackRouterService osRouterService = get(OpenstackRouterService.class);
IpAddress externalPeerIpAddress = IpAddress.valueOf(IpAddress.Version.INET, Ip4Address.valueOf(ipAddress).toOctets());
if (osNetAdminService.externalPeerRouters().isEmpty()) {
print(NO_ELEMENT);
return;
} else if (osNetAdminService.externalPeerRouters().stream().noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
print(NO_ELEMENT);
return;
}
Subnet subnet = osNetAdminService.subnets().stream().filter(s -> s.getGateway().equals(ipAddress)).findAny().orElse(null);
if (subnet == null) {
return;
}
Network network = osNetAdminService.network(subnet.getNetworkId());
if (network == null) {
return;
}
Router router = osRouterService.routers().stream().filter(r -> r.getExternalGatewayInfo().getNetworkId().equals(network.getId())).findAny().orElse(null);
if (router == null) {
return;
}
try {
if (vlanId.equals(NONE)) {
osNetAdminService.updateExternalPeerRouterVlan(externalPeerIpAddress, VlanId.NONE);
osNetAdminService.deriveExternalPeerRouterMac(router.getExternalGatewayInfo(), router, VlanId.NONE);
} else {
osNetAdminService.updateExternalPeerRouterVlan(externalPeerIpAddress, VlanId.vlanId(vlanId));
osNetAdminService.deriveExternalPeerRouterMac(router.getExternalGatewayInfo(), router, VlanId.vlanId(vlanId));
}
} catch (IllegalArgumentException e) {
log.error("Exception occurred because of {}", e.toString());
}
print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
List<ExternalPeerRouter> routers = Lists.newArrayList(osNetAdminService.externalPeerRouters());
for (ExternalPeerRouter r : routers) {
print(FORMAT, r.ipAddress(), r.macAddress().toString(), r.vlanId());
}
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method processGratuitousArpPacket.
private void processGratuitousArpPacket(NetFloatingIP floatingIP, InstancePort instancePort) {
Set<OpenstackNode> gws = ImmutableSet.copyOf(osNodeService.completeNodes(GATEWAY));
Network osNet = osNetworkService.network(instancePort.networkId());
OpenstackNode selectedGw = getGwByInstancePort(gws, instancePort);
ExternalPeerRouter externalPeerRouter = externalPeerRouterForNetwork(osNet, osNetworkService, osRouterAdminService);
if (externalPeerRouter == null) {
log.error("Failed to process GARP packet for floating ip {}, because ", NO_EXT_PEER_ROUTER_MSG);
return;
}
processGarpPacketForFloatingIp(floatingIP, instancePort, externalPeerRouter.vlanId(), selectedGw, packetService);
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method setFloatingIpRules.
private void setFloatingIpRules(NetFloatingIP floatingIp, InstancePort instPort, OpenstackNode gateway, ExternalPeerRouter peerRouter, boolean install) {
if (instPort == null) {
log.debug("No instance port found");
return;
}
Network osNet = osNetworkService.network(instPort.networkId());
ExternalPeerRouter externalPeerRouter = peerRouter != null ? peerRouter : externalPeerRouterForNetwork(osNet, osNetworkService, osRouterAdminService);
if (externalPeerRouter == null) {
log.warn("External peer router is not ready for now, " + "floating IP rules will be installed/uninstalled " + "when external peer router is available...");
return;
}
if (install) {
preCommitPortService.subscribePreCommit(instPort.portId(), OPENSTACK_PORT_PRE_REMOVE, this.getClass().getName());
log.info("Subscribed the port {} on listening pre-remove event", instPort.portId());
} else {
preCommitPortService.unsubscribePreCommit(instPort.portId(), OPENSTACK_PORT_PRE_REMOVE, instancePortService, this.getClass().getName());
log.info("Unsubscribed the port {} on listening pre-remove event", instPort.portId());
}
updateComputeNodeRules(instPort, osNet, gateway, install);
updateGatewayNodeRules(floatingIp, instPort, osNet, externalPeerRouter, gateway, install);
// TODO: need to refactor setUpstreamRules if possible
setUpstreamRules(floatingIp, osNet, instPort, externalPeerRouter, install);
log.trace("Succeeded to set flow rules for floating ip {}:{} and install: {}", floatingIp.getFloatingIpAddress(), floatingIp.getFixedIpAddress(), install);
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method routerUpdated.
private void routerUpdated(Router osRouter) {
ExternalGateway exGateway = osRouter.getExternalGatewayInfo();
ExternalPeerRouter externalPeerRouter = osNetworkAdminService.externalPeerRouter(exGateway);
VlanId vlanId = externalPeerRouter == null ? VlanId.NONE : externalPeerRouter.vlanId();
if (exGateway == null) {
deleteUnassociatedExternalPeerRouter();
osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> setSourceNat(iface, false));
} else {
osNetworkAdminService.deriveExternalPeerRouterMac(exGateway, osRouter, vlanId);
osRouterService.routerInterfaces(osRouter.getId()).forEach(iface -> setSourceNat(iface, exGateway.isEnableSnat()));
}
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackNetworkManager method updateExternalPeerRouter.
@Override
public void updateExternalPeerRouter(IpAddress ipAddress, MacAddress macAddress, VlanId vlanId) {
checkNotNull(ipAddress, ERR_NULL_PEER_ROUTER_IP);
ExternalPeerRouter existingPeerRouter = osNetworkStore.externalPeerRouter(ipAddress.toString());
if (existingPeerRouter != null) {
ExternalPeerRouter.Builder urBuilder = DefaultExternalPeerRouter.builder().ipAddress(ipAddress);
if (macAddress == null) {
urBuilder.macAddress(existingPeerRouter.macAddress());
} else {
urBuilder.macAddress(macAddress);
}
if (vlanId == null) {
urBuilder.vlanId(existingPeerRouter.vlanId());
} else {
urBuilder.vlanId(vlanId);
}
osNetworkStore.updateExternalPeerRouter(urBuilder.build());
}
}
Aggregations