use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class OpenstackNetworkingUtil method externalPeerRouterForNetwork.
/**
* Returns the external peer router with supplied network information.
*
* @param network network
* @param osNetworkService openstack network service
* @param osRouterAdminService openstack router admin service
* @return external peer router
*/
public static ExternalPeerRouter externalPeerRouterForNetwork(Network network, OpenstackNetworkService osNetworkService, OpenstackRouterAdminService osRouterAdminService) {
if (network == null) {
return null;
}
Subnet subnet = osNetworkService.subnets(network.getId()).stream().findAny().orElse(null);
if (subnet == null) {
return null;
}
RouterInterface osRouterIface = osRouterAdminService.routerInterfaces().stream().filter(i -> Objects.equals(i.getSubnetId(), subnet.getId())).findAny().orElse(null);
if (osRouterIface == null) {
return null;
}
Router osRouter = osRouterAdminService.router(osRouterIface.getId());
if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
return null;
}
ExternalGateway exGatewayInfo = osRouter.getExternalGatewayInfo();
return osNetworkService.externalPeerRouter(exGatewayInfo);
}
use of org.onosproject.openstacknetworking.api.ExternalPeerRouter in project onos by opennetworkinglab.
the class UpdateExternalPeerRouterCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkAdminService service = get(OpenstackNetworkAdminService.class);
IpAddress externalPeerIpAddress = IpAddress.valueOf(IpAddress.Version.INET, Ip4Address.valueOf(ipAddress).toOctets());
if (service.externalPeerRouters().isEmpty()) {
print(NO_ELEMENT);
return;
} else if (service.externalPeerRouters().stream().noneMatch(router -> router.ipAddress().toString().equals(ipAddress))) {
print(NO_ELEMENT);
return;
}
try {
if (vlanId.equals(NONE)) {
service.updateExternalPeerRouter(externalPeerIpAddress, MacAddress.valueOf(macAddress), VlanId.NONE);
} else {
service.updateExternalPeerRouter(externalPeerIpAddress, MacAddress.valueOf(macAddress), 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(service.externalPeerRouters());
for (ExternalPeerRouter router : routers) {
print(FORMAT, router.ipAddress(), router.macAddress().toString(), router.vlanId());
}
}
Aggregations