use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackDirectPortAddCommand method doExecute.
@Override
protected void doExecute() {
OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
DeviceService deviceService = get(DeviceService.class);
Port port = osNetService.port(portId);
if (port == null) {
log.error("There's no port that matches the port ID {}", portId);
return;
}
Optional<OpenstackNode> osNode = osNodeService.completeNodes(COMPUTE).stream().filter(node -> node.hostname().equals(port.getHostId())).findAny();
if (!osNode.isPresent()) {
log.error("There's no openstackNode that matches hostname {}", port.getHostId());
return;
}
String intfName = getIntfNameFromPciAddress(port);
if (intfName == null) {
log.error("Failed to retrieve interface name from a port {}", portId);
return;
} else if (intfName.equals(UNSUPPORTED_VENDOR)) {
return;
}
if (OpenstackNetworkingUtil.hasIntfAleadyInDevice(osNode.get().intgBridge(), intfName, deviceService)) {
log.error("Interface {} is already added to the device {}", osNode.get().intgBridge());
return;
}
log.info("Adding interface {} to the device {}..", intfName, osNode.get().intgBridge());
osNodeService.addVfPort(osNode.get(), intfName);
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackSwitchingHandler method setForwardingRulesForTunnel.
/**
* Configures the flow rules which are used for L2 packet switching.
* Note that these rules will be inserted in switching table (table 5).
*
* @param instPort instance port object
* @param install install flag, add the rule if true, remove it otherwise
*/
private void setForwardingRulesForTunnel(InstancePort instPort, boolean install) {
// switching rules for the instPorts in the same node
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(instPort.ipAddress().toIpPrefix()).matchTunnelId(getVni(instPort)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthDst(instPort.macAddress()).setOutput(instPort.portNumber()).build();
osFlowRuleService.setRule(appId, instPort.deviceId(), selector, treatment, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
// switching rules for the instPorts in the remote node
OpenstackNode localNode = osNodeService.node(instPort.deviceId());
if (localNode == null) {
final String error = String.format("Cannot find openstack node for %s", instPort.deviceId());
throw new IllegalStateException(error);
}
osNodeService.completeNodes(COMPUTE).stream().filter(remoteNode -> !remoteNode.intgBridge().equals(localNode.intgBridge())).forEach(remoteNode -> {
PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, remoteNode);
TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, remoteNode.intgBridge(), localNode.dataIp().getIp4Address()), remoteNode.intgBridge()).setOutput(portNum).build();
osFlowRuleService.setRule(appId, remoteNode.intgBridge(), selector, treatmentToRemote, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
});
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackSwitchingIcmpHandler method processRouterIntfEvent.
private void processRouterIntfEvent(Router osRouter, RouterInterface routerIface, boolean install) {
if (!getStatefulSnatFlag()) {
return;
}
Subnet osSubnet = osNetworkService.subnet(routerIface.getSubnetId());
Type netType = osNetworkService.networkType(osSubnet.getNetworkId());
String segId = osNetworkService.segmentId(osSubnet.getNetworkId());
IpAddress gatewayIp = IpAddress.valueOf(osSubnet.getGateway());
Set<Subnet> routableSubnets = routableSubnets(osRouter, osSubnet.getId());
osNodeService.completeNodes(COMPUTE).stream().filter(cNode -> cNode.dataIp() != null).forEach(cNode -> {
setRoutableSubnetsIcmpRules(cNode, segId, osSubnet, routableSubnets, gatewayIp, netType, install);
});
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackVtapManager method purgeVtap.
/**
* Purges all flow rules and group tables, tunneling interface for openstack vtap.
*/
@Override
public void purgeVtap() {
// Remove all flow rules
flowRuleService.removeFlowRulesById(appId);
// Remove all groups and tunnel interfaces
osNodeService.completeNodes(COMPUTE).stream().filter(osNode -> osNode.state() == COMPLETE).forEach(osNode -> {
groupService.getGroups(osNode.intgBridge(), appId).forEach(group -> groupService.removeGroup(osNode.intgBridge(), group.appCookie(), appId));
OpenstackVtapNetwork vtapNetwork = getVtapNetwork();
setTunnelInterface(osNode, vtapNetwork, false);
});
log.trace("{} all flow rules, groups, tunnel interface are purged", appId.name());
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackEastWestProbeCommand method doExecute.
@Override
protected void doExecute() {
OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
InstancePortService instPortService = get(InstancePortService.class);
MastershipService mastershipService = get(MastershipService.class);
ClusterService clusterService = get(ClusterService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
if (tsService == 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 node : osNodeService.completeNodes(COMPUTE)) {
if (!localNodeId.equals(mastershipService.getMasterFor(node.intgBridge()))) {
error("Current node is not the master for all compute 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
Set<InstancePort> activePorts = instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).collect(Collectors.toSet());
activePorts.forEach(srcPort -> activePorts.forEach(dstPort -> printReachability(tsService.probeEastWest(srcPort, dstPort))));
} else {
if (vmIps.length > 2) {
print("Too many VM IPs. The number of IP should be limited to 2.");
return;
}
IpAddress srcIp = getIpAddress(vmIps[0]);
if (srcIp == null) {
return;
}
InstancePort srcPort = instPort(instPortService, srcIp);
if (srcPort == null) {
print("Specified source IP is not existing.");
return;
}
final Set<IpAddress> dstIps = Sets.newConcurrentHashSet();
if (vmIps.length == 2) {
IpAddress dstIp = getIpAddress(vmIps[1]);
if (dstIp == null) {
return;
}
dstIps.add(dstIp);
}
if (vmIps.length == 1) {
dstIps.addAll(instPortService.instancePorts().stream().filter(p -> !p.ipAddress().equals(srcIp)).filter(p -> p.state().equals(InstancePort.State.ACTIVE)).map(InstancePort::ipAddress).collect(Collectors.toSet()));
}
printHeader();
dstIps.stream().filter(ip -> instPort(instPortService, ip) != null).map(ip -> instPort(instPortService, ip)).forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeEastWest(srcPort, port))));
}
}
Aggregations