use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackConfigStatefulSnatCommand method syncRules.
private void syncRules() {
// All handlers in this application reacts the node complete event and
// tries to re-configure flow rules for the complete node.
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
OpenstackNodeAdminService osNodeAdminService = get(OpenstackNodeAdminService.class);
if (osNodeService == null) {
error("Failed to re-install flow rules for OpenStack networking.");
return;
}
osNodeService.completeNodes().forEach(osNode -> {
OpenstackNode updated = osNode.updateState(NodeState.INIT);
osNodeAdminService.updateNode(updated);
});
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackDiffStateCommand method doExecute.
@Override
protected void doExecute() {
OpenstackSecurityGroupAdminService osSgService = get(OpenstackSecurityGroupAdminService.class);
OpenstackNetworkAdminService osNetService = get(OpenstackNetworkAdminService.class);
OpenstackRouterAdminService osRouterService = get(OpenstackRouterAdminService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
Map<String, String> headerMap = new HashMap<>();
headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
Optional<OpenstackNode> node = osNodeService.nodes(CONTROLLER).stream().findFirst();
if (!node.isPresent()) {
error("Keystone auth info has not been configured. " + "Please specify auth info via network-cfg.json.");
return;
}
OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
if (osClient == null) {
return;
}
if (!clear) {
show = true;
}
if (show && clear) {
error("Either --show (-s) or --clear (-c) option should be specified.");
}
if (show) {
print("\nComparing OpenStack floating IPs");
} else if (clear) {
print("\nClearing OpenStack floating IPs");
}
Set<String> cachedFips = osRouterService.floatingIps().stream().map(NetFloatingIP::getId).collect(Collectors.toSet());
Set<String> osFips = osClient.headers(headerMap).networking().floatingip().list().stream().map(NetFloatingIP::getId).collect(Collectors.toSet());
print(FLOATING_IP_FORMAT, "ID", "Floating IP", "Fixed IP");
getDiff(cachedFips, osFips).forEach(fipId -> {
printFloatingIp(osRouterService.floatingIp(fipId));
if (clear) {
osRouterService.removeFloatingIp(fipId);
}
});
Set<String> cachedPorts = osNetService.ports().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osPorts = osClient.headers(headerMap).networking().port().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
if (show) {
print("\nComparing OpenStack router interfaces");
} else if (clear) {
print("\nClearing OpenStack router interfaces");
}
print(ROUTER_INTF_FORMAT, "ID", "Tenant ID", "Subnet ID");
getDiff(cachedPorts, osPorts).forEach(portId -> {
RouterInterface ri = osRouterService.routerInterface(portId);
if (ri != null) {
printRouterIntf(ri);
if (clear) {
osRouterService.removeRouterInterface(portId);
}
}
});
if (show) {
print("\nComparing OpenStack ports");
} else if (clear) {
print("\nClearing OpenStack ports");
}
print(PORT_FORMAT, "ID", "Network", "MAC", "Fixed IPs");
getDiff(cachedPorts, osPorts).forEach(portId -> {
printPort(osNetService.port(portId), osNetService);
if (clear) {
osNetService.removePort(portId);
}
});
if (show) {
print("\nComparing OpenStack routers");
} else if (clear) {
print("\nClearing OpenStack routers");
}
Set<String> cachedRouters = osRouterService.routers().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osRouters = osClient.headers(headerMap).networking().router().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(ROUTER_FORMAT, "ID", "Name", "External", "Internal");
getDiff(cachedRouters, osRouters).forEach(routerId -> {
printRouter(osRouterService.router(routerId), osNetService);
if (clear) {
osRouterService.removeRouter(routerId);
}
});
if (show) {
print("\nComparing OpenStack subnets");
} else if (clear) {
print("\nClearing OpenStack subnets");
}
Set<String> cachedSubnets = osNetService.subnets().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osSubnets = osClient.headers(headerMap).networking().subnet().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(SUBNET_FORMAT, "ID", "Network", "CIDR");
getDiff(cachedSubnets, osSubnets).forEach(subnetId -> {
printSubnet(osNetService.subnet(subnetId), osNetService);
if (clear) {
osNetService.removeSubnet(subnetId);
}
});
if (show) {
print("\nComparing OpenStack networks");
} else if (clear) {
print("\nClearing OpenStack networks");
}
Set<String> cachedNets = osNetService.networks().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osNets = osClient.headers(headerMap).networking().network().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(NETWORK_FORMAT, "ID", "Name", "VNI", "Subnets");
getDiff(cachedNets, osNets).forEach(netId -> {
printNetwork(osNetService.network(netId));
if (clear) {
osNetService.removeNetwork(netId);
}
});
if (show) {
print("\nComparing OpenStack security groups");
} else if (clear) {
print("\nClearing OpenStack security groups");
}
Set<String> cachedSgs = osSgService.securityGroups().stream().map(IdEntity::getId).collect(Collectors.toSet());
Set<String> osSgs = osClient.headers(headerMap).networking().securitygroup().list().stream().map(IdEntity::getId).collect(Collectors.toSet());
print(SECURITY_GROUP_FORMAT, "ID", "Name");
getDiff(cachedSgs, osSgs).forEach(sgId -> {
printSecurityGroup(osSgService.securityGroup(sgId));
if (clear) {
osSgService.removeSecurityGroup(sgId);
}
});
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackNetworkingUtil method getGwByIndex.
/**
* Obtains gateway instance by giving index number.
*
* @param gws a collection of gateway nodes
* @param index index number
* @return gateway instance
*/
private static OpenstackNode getGwByIndex(Set<OpenstackNode> gws, int index) {
Map<String, OpenstackNode> hashMap = new HashMap<>();
gws.forEach(gw -> hashMap.put(gw.hostname(), gw));
TreeMap<String, OpenstackNode> treeMap = new TreeMap<>(hashMap);
Iterator<String> iteratorKey = treeMap.keySet().iterator();
int intIndex = 0;
OpenstackNode gw = null;
while (iteratorKey.hasNext()) {
String key = iteratorKey.next();
if (intIndex == index) {
gw = treeMap.get(key);
}
intIndex++;
}
return gw;
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setArpReplyRuleForGre.
/**
* Installs flow rules to match ARP reply packets only for GRE.
*
* @param port instance port
* @param install installation flag
*/
private void setArpReplyRuleForGre(InstancePort port, boolean install) {
OpenstackNode localNode = osNodeService.node(port.deviceId());
TrafficSelector selector = getArpReplySelectorForGre(port);
setLocalArpReplyTreatmentForGre(selector, port, install);
setRemoteArpTreatmentForTunnel(selector, port, localNode, install);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setFakeGatewayArpRule.
/**
* Installs flow rules which convert ARP request packet into ARP reply
* by adding a fake gateway MAC address as Source Hardware Address.
*
* @param osSubnet openstack subnet
* @param network openstack network
* @param install flag which indicates whether to install rule or remove rule
* @param osNode openstack node
*/
private void setFakeGatewayArpRule(Subnet osSubnet, Network network, boolean install, OpenstackNode osNode) {
if (ARP_BROADCAST_MODE.equals(getArpMode())) {
Type netType = osNetworkService.networkType(network.getId());
String gateway = osSubnet.getGateway();
if (gateway == null) {
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
if (netType == VLAN) {
sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
} else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
// different networks
if (!install) {
long numOfDupGws = osNetworkService.subnets().stream().filter(s -> !s.getId().equals(osSubnet.getId())).filter(s -> s.getGateway() != null).filter(s -> s.getGateway().equals(osSubnet.getGateway())).count();
if (numOfDupGws > 0) {
return;
}
}
}
sBuilder.matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(gateway));
if (osNode == null) {
osNodeService.completeNodes(COMPUTE).forEach(n -> {
Device device = deviceService.getDevice(n.intgBridge());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (netType == VLAN) {
tBuilder.popVlan();
}
tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setEthSrc(MacAddress.valueOf(gatewayMac)).setOutput(PortNumber.IN_PORT);
osFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
});
} else {
Device device = deviceService.getDevice(osNode.intgBridge());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (netType == VLAN) {
tBuilder.popVlan();
}
tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setOutput(PortNumber.IN_PORT);
osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
}
}
}
Aggregations