mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-15 17:31:31 +02:00
[ONOS-7627] Support the creation of sr-iov port type for LiquidIO smart NIC
Change-Id: I6d55d1dfd26ec6ed0b9df9fdeea31749b0c49b7c
This commit is contained in:
parent
d4066ea7fc
commit
c4d0640983
@ -15,8 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.openstacknetworking.api;
|
package org.onosproject.openstacknetworking.api;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import org.onlab.packet.MacAddress;
|
import org.onlab.packet.MacAddress;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides constants used in OpenStackSwitching.
|
* Provides constants used in OpenStackSwitching.
|
||||||
*/
|
*/
|
||||||
@ -35,6 +38,20 @@ public final class Constants {
|
|||||||
public static final MacAddress DEFAULT_GATEWAY_MAC = MacAddress.valueOf(DEFAULT_GATEWAY_MAC_STR);
|
public static final MacAddress DEFAULT_GATEWAY_MAC = MacAddress.valueOf(DEFAULT_GATEWAY_MAC_STR);
|
||||||
public static final MacAddress DEFAULT_EXTERNAL_ROUTER_MAC = MacAddress.valueOf("fe:00:00:00:00:01");
|
public static final MacAddress DEFAULT_EXTERNAL_ROUTER_MAC = MacAddress.valueOf("fe:00:00:00:00:01");
|
||||||
|
|
||||||
|
private static final String CAVIUM_PCI_VENDOR_INFO = "177d:9712";
|
||||||
|
private static final String PORT_NAME_PREFIX_CAVIUM = "enp";
|
||||||
|
public static final String PCI_VENDOR_INFO = "pci_vendor_info";
|
||||||
|
public static final String DIRECT = "direct";
|
||||||
|
public static final String PCISLOT = "pci_slot";
|
||||||
|
|
||||||
|
public static final Map<String, String> PORT_NAME_PREFIX_MAP = createPortNamePrefixMap();
|
||||||
|
private static Map<String, String> createPortNamePrefixMap() {
|
||||||
|
Map<String, String> portNamePrefixMap = Maps.newHashMap();
|
||||||
|
//Additional pci vendor information will be added
|
||||||
|
portNamePrefixMap.put(CAVIUM_PCI_VENDOR_INFO, PORT_NAME_PREFIX_CAVIUM);
|
||||||
|
return portNamePrefixMap;
|
||||||
|
}
|
||||||
|
|
||||||
public static final int PRIORITY_TUNNEL_TAG_RULE = 30000;
|
public static final int PRIORITY_TUNNEL_TAG_RULE = 30000;
|
||||||
public static final int PRIORITY_FLOATING_INTERNAL = 42000;
|
public static final int PRIORITY_FLOATING_INTERNAL = 42000;
|
||||||
public static final int PRIORITY_FLOATING_EXTERNAL = 41000;
|
public static final int PRIORITY_FLOATING_EXTERNAL = 41000;
|
||||||
|
@ -11,6 +11,8 @@ COMPILE_DEPS = [
|
|||||||
'//cli:onos-cli',
|
'//cli:onos-cli',
|
||||||
'//apps/openstacknode/api:onos-apps-openstacknode-api',
|
'//apps/openstacknode/api:onos-apps-openstacknode-api',
|
||||||
'//apps/openstacknetworking/api:onos-apps-openstacknetworking-api',
|
'//apps/openstacknetworking/api:onos-apps-openstacknetworking-api',
|
||||||
|
'//protocols/ovsdb/api:onos-protocols-ovsdb-api',
|
||||||
|
'//protocols/ovsdb/rfc:onos-protocols-ovsdb-rfc',
|
||||||
'//lib:openstack4j-core',
|
'//lib:openstack4j-core',
|
||||||
'//lib:openstack4j-http-connector',
|
'//lib:openstack4j-http-connector',
|
||||||
'//lib:openstack4j-httpclient',
|
'//lib:openstack4j-httpclient',
|
||||||
|
@ -113,6 +113,11 @@
|
|||||||
<classifier>tests</classifier>
|
<classifier>tests</classifier>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.onosproject</groupId>
|
||||||
|
<artifactId>onos-protocols-ovsdb-api</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.onosproject</groupId>
|
<groupId>org.onosproject</groupId>
|
||||||
<artifactId>onos-core-common</artifactId>
|
<artifactId>onos-core-common</artifactId>
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.openstacknetworking.cli;
|
||||||
|
|
||||||
|
import org.apache.karaf.shell.commands.Command;
|
||||||
|
import org.onosproject.cli.AbstractShellCommand;
|
||||||
|
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
|
||||||
|
import org.openstack4j.model.network.IP;
|
||||||
|
import org.openstack4j.model.network.Network;
|
||||||
|
import org.openstack4j.model.network.Port;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.DIRECT;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PCISLOT;
|
||||||
|
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists OpenStack direct ports.
|
||||||
|
*/
|
||||||
|
@Command(scope = "onos", name = "openstack-direct-ports",
|
||||||
|
description = "Lists all OpenStack direct ports")
|
||||||
|
public class OpenstackDirectPortListCommand extends AbstractShellCommand {
|
||||||
|
private static final String UNBOUND = "unbound";
|
||||||
|
private static final String FORMAT = "%-40s%-20s%-20s%-20s%-20s%-20s";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void execute() {
|
||||||
|
OpenstackNetworkService service = AbstractShellCommand.get(OpenstackNetworkService.class);
|
||||||
|
|
||||||
|
List<Port> ports = service.ports().stream()
|
||||||
|
|
||||||
|
.filter(port -> port.getvNicType().equals(DIRECT))
|
||||||
|
.filter(port -> port.isAdminStateUp() && !port.getVifType().equals(UNBOUND))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
|
||||||
|
print(FORMAT, "ID", "Network", "MAC", "FIXED IPs", "PCI Slot", "Interface");
|
||||||
|
for (Port port: ports) {
|
||||||
|
List<String> fixedIps = port.getFixedIps().stream()
|
||||||
|
.map(IP::getIpAddress)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
Network osNet = service.network(port.getNetworkId());
|
||||||
|
print(FORMAT, port.getId(),
|
||||||
|
osNet.getName(),
|
||||||
|
port.getMacAddress(),
|
||||||
|
fixedIps.isEmpty() ? "" : fixedIps,
|
||||||
|
port.getProfile() == null ? "" : port.getProfile().get(PCISLOT).toString(),
|
||||||
|
getIntfNameFromPciAddress(port));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,246 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.openstacknetworking.impl;
|
||||||
|
|
||||||
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
|
import org.apache.felix.scr.annotations.Component;
|
||||||
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
|
import org.apache.felix.scr.annotations.Modified;
|
||||||
|
import org.apache.felix.scr.annotations.Property;
|
||||||
|
import org.apache.felix.scr.annotations.Reference;
|
||||||
|
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||||
|
import org.onlab.util.Tools;
|
||||||
|
import org.onosproject.cfg.ComponentConfigService;
|
||||||
|
import org.onosproject.cluster.ClusterService;
|
||||||
|
import org.onosproject.cluster.LeadershipService;
|
||||||
|
import org.onosproject.cluster.NodeId;
|
||||||
|
import org.onosproject.core.ApplicationId;
|
||||||
|
import org.onosproject.core.CoreService;
|
||||||
|
import org.onosproject.mastership.MastershipService;
|
||||||
|
import org.onosproject.net.DeviceId;
|
||||||
|
import org.onosproject.net.device.DeviceService;
|
||||||
|
import org.onosproject.openstacknetworking.api.InstancePort;
|
||||||
|
import org.onosproject.openstacknetworking.api.InstancePortService;
|
||||||
|
import org.onosproject.openstacknetworking.api.OpenstackNetworkEvent;
|
||||||
|
import org.onosproject.openstacknetworking.api.OpenstackNetworkListener;
|
||||||
|
import org.onosproject.openstacknetworking.api.OpenstackNetworkService;
|
||||||
|
import org.onosproject.openstacknode.api.OpenstackNode;
|
||||||
|
import org.onosproject.openstacknode.api.OpenstackNodeService;
|
||||||
|
import org.onosproject.ovsdb.controller.OvsdbController;
|
||||||
|
import org.openstack4j.model.network.Port;
|
||||||
|
import org.openstack4j.model.network.State;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Dictionary;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.DIRECT;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
|
||||||
|
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress;
|
||||||
|
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE;
|
||||||
|
|
||||||
|
@Component(immediate = true)
|
||||||
|
public final class OpenStackSwitchingDirectPortProvider {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
private static final String OVSDB_PORT = "ovsdbPortNum";
|
||||||
|
private static final int DEFAULT_OVSDB_PORT = 6640;
|
||||||
|
private static final String UNBOUND = "unbound";
|
||||||
|
private static final String PORT_NAME = "portName";
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected CoreService coreService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected OpenstackNetworkService osNetworkService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected OpenstackNodeService osNodeService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected LeadershipService leadershipService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected ClusterService clusterService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected OvsdbController ovsdbController;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected DeviceService deviceService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected InstancePortService instancePortService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected ComponentConfigService componentConfigService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected MastershipService mastershipService;
|
||||||
|
|
||||||
|
@Property(name = OVSDB_PORT, intValue = DEFAULT_OVSDB_PORT,
|
||||||
|
label = "OVSDB server listen port")
|
||||||
|
private int ovsdbPort = DEFAULT_OVSDB_PORT;
|
||||||
|
|
||||||
|
private final OpenstackNetworkListener openstackNetworkListener = new InternalOpenstackNetworkListener();
|
||||||
|
|
||||||
|
private NodeId localNodeId;
|
||||||
|
private ApplicationId appId;
|
||||||
|
|
||||||
|
@Activate
|
||||||
|
void activate() {
|
||||||
|
appId = coreService.registerApplication(OPENSTACK_NETWORKING_APP_ID);
|
||||||
|
localNodeId = clusterService.getLocalNode().id();
|
||||||
|
leadershipService.runForLeadership(appId.name());
|
||||||
|
osNetworkService.addListener(openstackNetworkListener);
|
||||||
|
componentConfigService.registerProperties(getClass());
|
||||||
|
|
||||||
|
log.info("Started");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deactivate
|
||||||
|
void deactivate() {
|
||||||
|
leadershipService.withdraw(appId.name());
|
||||||
|
osNetworkService.removeListener(openstackNetworkListener);
|
||||||
|
componentConfigService.unregisterProperties(getClass(), false);
|
||||||
|
|
||||||
|
log.info("Stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Modified
|
||||||
|
protected void modified(ComponentContext context) {
|
||||||
|
Dictionary<?, ?> properties = context.getProperties();
|
||||||
|
int updatedOvsdbPort = Tools.getIntegerProperty(properties, OVSDB_PORT);
|
||||||
|
if (!Objects.equals(updatedOvsdbPort, ovsdbPort)) {
|
||||||
|
ovsdbPort = updatedOvsdbPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Modified");
|
||||||
|
}
|
||||||
|
private void processPortAdded(Port port) {
|
||||||
|
if (!port.getvNicType().equals(DIRECT)) {
|
||||||
|
log.trace("processPortAdded skipped because of unsupported vNicType: {}", port.getvNicType());
|
||||||
|
return;
|
||||||
|
} else if (!port.isAdminStateUp() || port.getVifType().equals(UNBOUND)) {
|
||||||
|
log.trace("processPortAdded skipped because of status: {}, adminStateUp: {}, vifType: {}",
|
||||||
|
port.getState(), port.isAdminStateUp(), port.getVifType());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
InstancePort instancePort = instancePortService.instancePort(port.getId());
|
||||||
|
//Skip this if the instance port for the port id is already created.
|
||||||
|
if (instancePort != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<OpenstackNode> osNode = osNodeService.completeNodes(COMPUTE).stream()
|
||||||
|
.filter(node -> node.hostname().equals(port.getHostId()))
|
||||||
|
.findAny();
|
||||||
|
if (!osNode.isPresent()) {
|
||||||
|
log.error("processPortAdded failed because openstackNode doesn't exist that matches hostname {}",
|
||||||
|
port.getHostId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.trace("Retrieved openstackNode: {}", osNode.get().toString());
|
||||||
|
|
||||||
|
String intfName = getIntfNameFromPciAddress(port);
|
||||||
|
if (intfName == null) {
|
||||||
|
log.error("Failed to execute processPortAdded because of null interface name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.trace("Retrieved interface name: {}", intfName);
|
||||||
|
|
||||||
|
osNodeService.addVfPort(osNode.get(), intfName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processPortRemoved(Port port) {
|
||||||
|
if (!port.getvNicType().equals(DIRECT)) {
|
||||||
|
log.trace("processPortRemoved skipped because of unsupported vNicType: {}", port.getvNicType());
|
||||||
|
return;
|
||||||
|
} else if (instancePortService.instancePort(port.getId()) == null) {
|
||||||
|
log.trace("processPortRemoved skipped because no instance port exist for portId: {}", port.getId());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
InstancePort instancePort = instancePortService.instancePort(port.getId());
|
||||||
|
if (instancePort == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DeviceId deviceId = instancePort.deviceId();
|
||||||
|
if (deviceId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OpenstackNode osNode = osNodeService.node(deviceId);
|
||||||
|
if (osNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<org.onosproject.net.Port> removedPort = deviceService.getPorts(deviceId).stream()
|
||||||
|
.filter(p -> Objects.equals(p.number(), instancePort.portNumber()))
|
||||||
|
.findAny();
|
||||||
|
|
||||||
|
if (!removedPort.isPresent()) {
|
||||||
|
log.error("Failed to execute processPortAdded because port number doesn't exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String intfName = removedPort.get().annotations().value(PORT_NAME);
|
||||||
|
|
||||||
|
if (intfName == null) {
|
||||||
|
log.error("Failed to execute processPortAdded because of null interface name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.trace("Retrieved interface name: {}", intfName);
|
||||||
|
|
||||||
|
osNodeService.removeVfPort(osNode, intfName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InternalOpenstackNetworkListener implements OpenstackNetworkListener {
|
||||||
|
@Override
|
||||||
|
public boolean isRelevant(OpenstackNetworkEvent event) {
|
||||||
|
// do not allow to proceed without leadership
|
||||||
|
NodeId leader = leadershipService.getLeader(appId.name());
|
||||||
|
if (!Objects.equals(localNodeId, leader)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void event(OpenstackNetworkEvent event) {
|
||||||
|
switch (event.type()) {
|
||||||
|
case OPENSTACK_PORT_UPDATED:
|
||||||
|
if (event.port().getState() == State.DOWN) {
|
||||||
|
processPortRemoved(event.port());
|
||||||
|
} else {
|
||||||
|
processPortAdded(event.port());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case OPENSTACK_PORT_REMOVED:
|
||||||
|
processPortRemoved(event.port());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -69,6 +69,10 @@ import java.util.stream.Collectors;
|
|||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
|
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.DIRECT;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PCISLOT;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_MAP;
|
||||||
|
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress;
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,6 +109,8 @@ public class OpenstackNetworkManager
|
|||||||
private static final String ERR_NOT_FOUND = " does not exist";
|
private static final String ERR_NOT_FOUND = " does not exist";
|
||||||
private static final String ERR_IN_USE = " still in use";
|
private static final String ERR_IN_USE = " still in use";
|
||||||
private static final String ERR_DUPLICATE = " already exists";
|
private static final String ERR_DUPLICATE = " already exists";
|
||||||
|
private static final String PORT_NAME_PREFIX_VM = "tap";
|
||||||
|
|
||||||
|
|
||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected CoreService coreService;
|
protected CoreService coreService;
|
||||||
@ -312,11 +318,28 @@ public class OpenstackNetworkManager
|
|||||||
if (Strings.isNullOrEmpty(portName)) {
|
if (Strings.isNullOrEmpty(portName)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Optional<Port> osPort = osNetworkStore.ports()
|
|
||||||
.stream()
|
if (port.annotations().value(PORT_NAME).startsWith(PORT_NAME_PREFIX_VM)) {
|
||||||
.filter(p -> p.getId().contains(portName.substring(3)))
|
Optional<Port> osPort = osNetworkStore.ports()
|
||||||
.findFirst();
|
.stream()
|
||||||
return osPort.orElse(null);
|
.filter(p -> p.getId().contains(portName.substring(3)))
|
||||||
|
.findFirst();
|
||||||
|
return osPort.orElse(null);
|
||||||
|
} else if (isDirectPort(portName)) {
|
||||||
|
//Additional prefixes will be added
|
||||||
|
Optional<Port> osPort = osNetworkStore.ports()
|
||||||
|
.stream()
|
||||||
|
.filter(p -> p.getvNicType().equals(DIRECT) && p.getProfile().get(PCISLOT) != null)
|
||||||
|
.filter(p -> getIntfNameFromPciAddress(p).equals(portName))
|
||||||
|
.findFirst();
|
||||||
|
return osPort.orElse(null);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDirectPort(String portName) {
|
||||||
|
return PORT_NAME_PREFIX_MAP.values().stream().filter(p -> portName.startsWith(p)).findAny().isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -213,7 +213,6 @@ public class OpenstackRoutingHandler {
|
|||||||
setRouterAdminRules(network.getProviderSegID(), network.getNetworkType(), !osRouter.isAdminStateUp());
|
setRouterAdminRules(network.getProviderSegID(), network.getNetworkType(), !osRouter.isAdminStateUp());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ExternalPeerRouter externalPeerRouter = osNetworkAdminService.externalPeerRouter(exGateway);
|
ExternalPeerRouter externalPeerRouter = osNetworkAdminService.externalPeerRouter(exGateway);
|
||||||
VlanId vlanId = externalPeerRouter == null ? VlanId.NONE : externalPeerRouter.externalPeerRouterVlanId();
|
VlanId vlanId = externalPeerRouter == null ? VlanId.NONE : externalPeerRouter.externalPeerRouterVlanId();
|
||||||
|
|
||||||
|
@ -64,6 +64,7 @@ import java.util.stream.Collectors;
|
|||||||
import static org.onlab.util.Tools.groupedThreads;
|
import static org.onlab.util.Tools.groupedThreads;
|
||||||
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
|
import static org.onosproject.net.AnnotationKeys.PORT_NAME;
|
||||||
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
|
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_MAP;
|
||||||
import static org.onosproject.openstacknetworking.impl.HostBasedInstancePort.ANNOTATION_CREATE_TIME;
|
import static org.onosproject.openstacknetworking.impl.HostBasedInstancePort.ANNOTATION_CREATE_TIME;
|
||||||
import static org.onosproject.openstacknetworking.impl.HostBasedInstancePort.ANNOTATION_NETWORK_ID;
|
import static org.onosproject.openstacknetworking.impl.HostBasedInstancePort.ANNOTATION_NETWORK_ID;
|
||||||
import static org.onosproject.openstacknetworking.impl.HostBasedInstancePort.ANNOTATION_PORT_ID;
|
import static org.onosproject.openstacknetworking.impl.HostBasedInstancePort.ANNOTATION_PORT_ID;
|
||||||
@ -75,6 +76,7 @@ public final class OpenstackSwitchingHostProvider extends AbstractProvider imple
|
|||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
private static final String PORT_NAME_PREFIX_VM = "tap";
|
private static final String PORT_NAME_PREFIX_VM = "tap";
|
||||||
|
private static final String PORT_NAME_PREFIX_CAVIUM = "enp";
|
||||||
private static final String ERR_ADD_HOST = "Failed to add host: ";
|
private static final String ERR_ADD_HOST = "Failed to add host: ";
|
||||||
private static final String ANNOTATION_SEGMENT_ID = "segId";
|
private static final String ANNOTATION_SEGMENT_ID = "segId";
|
||||||
private static final String SONA_HOST_SCHEME = "sona";
|
private static final String SONA_HOST_SCHEME = "sona";
|
||||||
@ -229,11 +231,16 @@ public final class OpenstackSwitchingHostProvider extends AbstractProvider imple
|
|||||||
String portName = port.annotations().value(PORT_NAME);
|
String portName = port.annotations().value(PORT_NAME);
|
||||||
|
|
||||||
return !Strings.isNullOrEmpty(portName) &&
|
return !Strings.isNullOrEmpty(portName) &&
|
||||||
portName.startsWith(PORT_NAME_PREFIX_VM);
|
(portName.startsWith(PORT_NAME_PREFIX_VM) || isDirectPort(portName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDirectPort(String portName) {
|
||||||
|
return PORT_NAME_PREFIX_MAP.values().stream().filter(p -> portName.startsWith(p)).findAny().isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void event(DeviceEvent event) {
|
public void event(DeviceEvent event) {
|
||||||
|
log.info("Device event occurred with type {}", event.type());
|
||||||
switch (event.type()) {
|
switch (event.type()) {
|
||||||
case PORT_UPDATED:
|
case PORT_UPDATED:
|
||||||
if (!event.port().isEnabled()) {
|
if (!event.port().isEnabled()) {
|
||||||
@ -335,6 +342,19 @@ public final class OpenstackSwitchingHostProvider extends AbstractProvider imple
|
|||||||
processPortAdded(port);
|
processPortAdded(port);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
PORT_NAME_PREFIX_MAP.values().forEach(portNamePrefix -> {
|
||||||
|
deviceService.getPorts(osNode.intgBridge()).stream()
|
||||||
|
.filter(port -> port.annotations().value(PORT_NAME)
|
||||||
|
.startsWith(portNamePrefix) &&
|
||||||
|
port.isEnabled())
|
||||||
|
.forEach(port -> {
|
||||||
|
log.debug("Instance port {} is detected from {}",
|
||||||
|
port.annotations().value(portNamePrefix),
|
||||||
|
osNode.hostname());
|
||||||
|
processPortAdded(port);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Tools.stream(hostService.getHosts())
|
Tools.stream(hostService.getHosts())
|
||||||
.filter(host -> deviceService.getPort(
|
.filter(host -> deviceService.getPort(
|
||||||
host.location().deviceId(),
|
host.location().deviceId(),
|
||||||
|
@ -22,6 +22,7 @@ import org.onosproject.net.DeviceId;
|
|||||||
import org.onosproject.openstacknode.api.OpenstackNode;
|
import org.onosproject.openstacknode.api.OpenstackNode;
|
||||||
import org.openstack4j.core.transport.ObjectMapperSingleton;
|
import org.openstack4j.core.transport.ObjectMapperSingleton;
|
||||||
import org.openstack4j.model.ModelEntity;
|
import org.openstack4j.model.ModelEntity;
|
||||||
|
import org.openstack4j.model.network.Port;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -33,6 +34,9 @@ import java.util.Set;
|
|||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
|
import static com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PCISLOT;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PCI_VENDOR_INFO;
|
||||||
|
import static org.onosproject.openstacknetworking.api.Constants.PORT_NAME_PREFIX_MAP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An utility that used in openstack networking app.
|
* An utility that used in openstack networking app.
|
||||||
@ -41,6 +45,11 @@ public final class OpenstackNetworkingUtil {
|
|||||||
|
|
||||||
protected static final Logger log = LoggerFactory.getLogger(OpenstackNetworkingUtil.class);
|
protected static final Logger log = LoggerFactory.getLogger(OpenstackNetworkingUtil.class);
|
||||||
|
|
||||||
|
private static final int HEX_RADIX = 16;
|
||||||
|
private static final int ZERO_FUNCTION_NUMBER = 0;
|
||||||
|
private static final String PREFIX_DEVICE_NUMBER = "s";
|
||||||
|
private static final String PREFIX_FUNCTION_NUMBER = "f";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prevents object instantiation from external.
|
* Prevents object instantiation from external.
|
||||||
*/
|
*/
|
||||||
@ -125,4 +134,51 @@ public final class OpenstackNetworkingUtil {
|
|||||||
}
|
}
|
||||||
return gw;
|
return gw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the interface name with the supplied port.
|
||||||
|
*
|
||||||
|
* @param port port
|
||||||
|
* @return interface name
|
||||||
|
*/
|
||||||
|
public static String getIntfNameFromPciAddress(Port port) {
|
||||||
|
if (port.getProfile() != null && port.getProfile().get(PCISLOT) == null) {
|
||||||
|
log.error("Failed to retrieve the interface name because of no pci_slot information from the port");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String busNumHex = port.getProfile().get(PCISLOT).toString().split(":")[1];
|
||||||
|
String busNumDecimal = String.valueOf(Integer.parseInt(busNumHex, HEX_RADIX));
|
||||||
|
|
||||||
|
String deviceNumHex = port.getProfile().get(PCISLOT).toString()
|
||||||
|
.split(":")[2]
|
||||||
|
.split("\\.")[0];
|
||||||
|
String deviceNumDecimal = String.valueOf(Integer.parseInt(deviceNumHex, HEX_RADIX));
|
||||||
|
|
||||||
|
String functionNumHex = port.getProfile().get(PCISLOT).toString()
|
||||||
|
.split(":")[2]
|
||||||
|
.split("\\.")[1];
|
||||||
|
String functionNumDecimal = String.valueOf(Integer.parseInt(functionNumHex, HEX_RADIX));
|
||||||
|
|
||||||
|
String intfName;
|
||||||
|
|
||||||
|
String vendorInfoForPort = String.valueOf(port.getProfile().get(PCI_VENDOR_INFO));
|
||||||
|
|
||||||
|
if (vendorInfoForPort == null) {
|
||||||
|
log.error("Failed to retrieve the interface name because of no pci vendor information from the port");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String portNamePrefix = PORT_NAME_PREFIX_MAP.get(vendorInfoForPort);
|
||||||
|
if (vendorInfoForPort == null) {
|
||||||
|
log.error("Failed to retrieve the interface name because of no prefix information from the port");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (functionNumDecimal.equals(ZERO_FUNCTION_NUMBER)) {
|
||||||
|
intfName = portNamePrefix + busNumDecimal + PREFIX_DEVICE_NUMBER + deviceNumDecimal;
|
||||||
|
} else {
|
||||||
|
intfName = portNamePrefix + busNumDecimal + PREFIX_DEVICE_NUMBER + deviceNumDecimal
|
||||||
|
+ PREFIX_FUNCTION_NUMBER + functionNumDecimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
return intfName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
<command>
|
<command>
|
||||||
<action class="org.onosproject.openstacknetworking.cli.OpenstackPortListCommand"/>
|
<action class="org.onosproject.openstacknetworking.cli.OpenstackPortListCommand"/>
|
||||||
</command>
|
</command>
|
||||||
|
<command>
|
||||||
|
<action class="org.onosproject.openstacknetworking.cli.OpenstackDirectPortListCommand"/>
|
||||||
|
</command>
|
||||||
<command>
|
<command>
|
||||||
<action class="org.onosproject.openstacknetworking.cli.OpenstackRouterListCommand"/>
|
<action class="org.onosproject.openstacknetworking.cli.OpenstackRouterListCommand"/>
|
||||||
</command>
|
</command>
|
||||||
|
@ -631,6 +631,14 @@ public class OpenstackNetworkManagerTest {
|
|||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addListener(OpenstackNodeListener listener) {
|
public void addListener(OpenstackNodeListener listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
|
@ -57,6 +57,15 @@ public class OpenstackNodeServiceAdapter implements OpenstackNodeService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addListener(OpenstackNodeListener listener) {
|
public void addListener(OpenstackNodeListener listener) {
|
||||||
|
|
||||||
|
@ -75,4 +75,20 @@ public interface OpenstackNodeService extends ListenerService<OpenstackNodeEvent
|
|||||||
* @return openstack node
|
* @return openstack node
|
||||||
*/
|
*/
|
||||||
OpenstackNode node(DeviceId deviceId);
|
OpenstackNode node(DeviceId deviceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the vf port to the given openstack node.
|
||||||
|
*
|
||||||
|
* @param osNode openstack node
|
||||||
|
* @param portName port name
|
||||||
|
*/
|
||||||
|
void addVfPort(OpenstackNode osNode, String portName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes vf port to the given openstack node.
|
||||||
|
*
|
||||||
|
* @param osNode openstack node
|
||||||
|
* @param portName port name
|
||||||
|
*/
|
||||||
|
void removeVfPort(OpenstackNode osNode, String portName);
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,7 @@ import org.onosproject.openstacknode.api.OpenstackNodeHandler;
|
|||||||
import org.onosproject.openstacknode.api.OpenstackNodeListener;
|
import org.onosproject.openstacknode.api.OpenstackNodeListener;
|
||||||
import org.onosproject.openstacknode.api.OpenstackNodeService;
|
import org.onosproject.openstacknode.api.OpenstackNodeService;
|
||||||
import org.onosproject.openstacknode.api.OpenstackPhyInterface;
|
import org.onosproject.openstacknode.api.OpenstackPhyInterface;
|
||||||
import org.onosproject.ovsdb.controller.OvsdbClientService;
|
|
||||||
import org.onosproject.ovsdb.controller.OvsdbController;
|
import org.onosproject.ovsdb.controller.OvsdbController;
|
||||||
import org.onosproject.ovsdb.controller.OvsdbNodeId;
|
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@ -84,6 +82,7 @@ import static org.onosproject.openstacknode.api.NodeState.DEVICE_CREATED;
|
|||||||
import static org.onosproject.openstacknode.api.NodeState.INCOMPLETE;
|
import static org.onosproject.openstacknode.api.NodeState.INCOMPLETE;
|
||||||
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
|
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
|
||||||
import static org.onosproject.openstacknode.api.OpenstackNodeService.APP_ID;
|
import static org.onosproject.openstacknode.api.OpenstackNodeService.APP_ID;
|
||||||
|
import static org.onosproject.openstacknode.util.OpenstackNodeUtil.isOvsdbConnected;
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,8 +94,8 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
private final Logger log = getLogger(getClass());
|
private final Logger log = getLogger(getClass());
|
||||||
|
|
||||||
private static final String OVSDB_PORT = "ovsdbPortNum";
|
private static final String OVSDB_PORT = "ovsdbPortNum";
|
||||||
private static final int DEFAULT_OVSDB_PORT = 6640;
|
|
||||||
private static final String DEFAULT_OF_PROTO = "tcp";
|
private static final String DEFAULT_OF_PROTO = "tcp";
|
||||||
|
private static final int DEFAULT_OVSDB_PORT = 6640;
|
||||||
private static final int DEFAULT_OFPORT = 6653;
|
private static final int DEFAULT_OFPORT = 6653;
|
||||||
private static final int DPID_BEGIN = 3;
|
private static final int DPID_BEGIN = 3;
|
||||||
|
|
||||||
@ -180,7 +179,7 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processInitState(OpenstackNode osNode) {
|
public void processInitState(OpenstackNode osNode) {
|
||||||
if (!isOvsdbConnected(osNode)) {
|
if (!isOvsdbConnected(osNode, ovsdbPort, ovsdbController, deviceService)) {
|
||||||
ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort));
|
ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -192,13 +191,13 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void processDeviceCreatedState(OpenstackNode osNode) {
|
public void processDeviceCreatedState(OpenstackNode osNode) {
|
||||||
try {
|
try {
|
||||||
if (!isOvsdbConnected(osNode)) {
|
if (!isOvsdbConnected(osNode, ovsdbPort, ovsdbController, deviceService)) {
|
||||||
ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort));
|
ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (osNode.type() == GATEWAY) {
|
if (osNode.type() == GATEWAY) {
|
||||||
addSystemInterface(osNode, INTEGRATION_BRIDGE, osNode.uplinkPort());
|
addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, osNode.uplinkPort(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (osNode.dataIp() != null &&
|
if (osNode.dataIp() != null &&
|
||||||
@ -208,12 +207,12 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
|
|
||||||
if (osNode.vlanIntf() != null &&
|
if (osNode.vlanIntf() != null &&
|
||||||
!isIntfEnabled(osNode, osNode.vlanIntf())) {
|
!isIntfEnabled(osNode, osNode.vlanIntf())) {
|
||||||
addSystemInterface(osNode, INTEGRATION_BRIDGE, osNode.vlanIntf());
|
addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, osNode.vlanIntf(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
osNode.phyIntfs().forEach(i -> {
|
osNode.phyIntfs().forEach(i -> {
|
||||||
if (!isIntfEnabled(osNode, i.intf())) {
|
if (!isIntfEnabled(osNode, i.intf())) {
|
||||||
addSystemInterface(osNode, INTEGRATION_BRIDGE, i.intf());
|
addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, i.intf(), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -224,11 +223,7 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processCompleteState(OpenstackNode osNode) {
|
public void processCompleteState(OpenstackNode osNode) {
|
||||||
OvsdbClientService ovsdbClient = ovsdbController.getOvsdbClient(
|
//Do something if needed
|
||||||
new OvsdbNodeId(osNode.managementIp(), DEFAULT_OVSDB_PORT));
|
|
||||||
if (ovsdbClient != null && ovsdbClient.isConnected()) {
|
|
||||||
ovsdbClient.disconnect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -236,21 +231,6 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether the controller has a connection with an OVSDB that resides
|
|
||||||
* inside the given openstack node.
|
|
||||||
*
|
|
||||||
* @param osNode openstack node
|
|
||||||
* @return true if the controller is connected to the OVSDB, false otherwise
|
|
||||||
*/
|
|
||||||
private boolean isOvsdbConnected(OpenstackNode osNode) {
|
|
||||||
OvsdbNodeId ovsdb = new OvsdbNodeId(osNode.managementIp(), ovsdbPort);
|
|
||||||
OvsdbClientService client = ovsdbController.getOvsdbClient(ovsdb);
|
|
||||||
return deviceService.isAvailable(osNode.ovsdb()) &&
|
|
||||||
client != null &&
|
|
||||||
client.isConnected();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a bridge with a given name on a given openstack node.
|
* Creates a bridge with a given name on a given openstack node.
|
||||||
*
|
*
|
||||||
@ -288,19 +268,27 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a network interface (aka port) into a given bridge of openstack node.
|
* Adds or removes a network interface (aka port) into a given bridge of openstack node.
|
||||||
*
|
*
|
||||||
* @param osNode openstack node
|
* @param osNode openstack node
|
||||||
* @param bridgeName bridge name
|
* @param bridgeName bridge name
|
||||||
* @param intfName interface name
|
* @param intfName interface name
|
||||||
|
* @param addOrRemove add port is true, remove it otherwise
|
||||||
*/
|
*/
|
||||||
private void addSystemInterface(OpenstackNode osNode, String bridgeName, String intfName) {
|
private void addOrRemoveSystemInterface(OpenstackNode osNode, String bridgeName, String intfName,
|
||||||
|
boolean addOrRemove) {
|
||||||
Device device = deviceService.getDevice(osNode.ovsdb());
|
Device device = deviceService.getDevice(osNode.ovsdb());
|
||||||
if (device == null || !device.is(BridgeConfig.class)) {
|
if (device == null || !device.is(BridgeConfig.class)) {
|
||||||
|
log.info("device is null or this device if not ovsdb device");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
|
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
|
||||||
bridgeConfig.addPort(BridgeName.bridgeName(bridgeName), intfName);
|
|
||||||
|
if (addOrRemove) {
|
||||||
|
bridgeConfig.addPort(BridgeName.bridgeName(bridgeName), intfName);
|
||||||
|
} else {
|
||||||
|
bridgeConfig.deletePort(BridgeName.bridgeName(bridgeName), intfName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,6 +365,10 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
private boolean isCurrentStateDone(OpenstackNode osNode) {
|
private boolean isCurrentStateDone(OpenstackNode osNode) {
|
||||||
switch (osNode.state()) {
|
switch (osNode.state()) {
|
||||||
case INIT:
|
case INIT:
|
||||||
|
if (!isOvsdbConnected(osNode, ovsdbPort, ovsdbController, deviceService)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return deviceService.isAvailable(osNode.intgBridge());
|
return deviceService.isAvailable(osNode.intgBridge());
|
||||||
case DEVICE_CREATED:
|
case DEVICE_CREATED:
|
||||||
if (osNode.dataIp() != null &&
|
if (osNode.dataIp() != null &&
|
||||||
@ -465,9 +457,6 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
|||||||
if (deviceService.isAvailable(device.id())) {
|
if (deviceService.isAvailable(device.id())) {
|
||||||
log.debug("OVSDB {} detected", device.id());
|
log.debug("OVSDB {} detected", device.id());
|
||||||
bootstrapNode(osNode);
|
bootstrapNode(osNode);
|
||||||
} else if (osNode.state() == COMPLETE) {
|
|
||||||
log.debug("Removing OVSDB {}", device.id());
|
|
||||||
deviceAdminService.removeDevice(device.id());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -20,15 +20,22 @@ import com.google.common.collect.ImmutableSet;
|
|||||||
import org.apache.felix.scr.annotations.Activate;
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
import org.apache.felix.scr.annotations.Component;
|
import org.apache.felix.scr.annotations.Component;
|
||||||
import org.apache.felix.scr.annotations.Deactivate;
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
|
import org.apache.felix.scr.annotations.Modified;
|
||||||
|
import org.apache.felix.scr.annotations.Property;
|
||||||
import org.apache.felix.scr.annotations.Reference;
|
import org.apache.felix.scr.annotations.Reference;
|
||||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||||
import org.apache.felix.scr.annotations.Service;
|
import org.apache.felix.scr.annotations.Service;
|
||||||
|
import org.onlab.util.Tools;
|
||||||
import org.onosproject.cluster.ClusterService;
|
import org.onosproject.cluster.ClusterService;
|
||||||
import org.onosproject.cluster.LeadershipService;
|
import org.onosproject.cluster.LeadershipService;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
import org.onosproject.event.ListenerRegistry;
|
import org.onosproject.event.ListenerRegistry;
|
||||||
|
import org.onosproject.net.Device;
|
||||||
import org.onosproject.net.DeviceId;
|
import org.onosproject.net.DeviceId;
|
||||||
|
import org.onosproject.net.behaviour.BridgeConfig;
|
||||||
|
import org.onosproject.net.behaviour.BridgeName;
|
||||||
|
import org.onosproject.net.device.DeviceService;
|
||||||
import org.onosproject.openstacknode.api.OpenstackNode;
|
import org.onosproject.openstacknode.api.OpenstackNode;
|
||||||
import org.onosproject.openstacknode.api.OpenstackNodeAdminService;
|
import org.onosproject.openstacknode.api.OpenstackNodeAdminService;
|
||||||
import org.onosproject.openstacknode.api.OpenstackNodeEvent;
|
import org.onosproject.openstacknode.api.OpenstackNodeEvent;
|
||||||
@ -36,8 +43,12 @@ import org.onosproject.openstacknode.api.OpenstackNodeListener;
|
|||||||
import org.onosproject.openstacknode.api.OpenstackNodeService;
|
import org.onosproject.openstacknode.api.OpenstackNodeService;
|
||||||
import org.onosproject.openstacknode.api.OpenstackNodeStore;
|
import org.onosproject.openstacknode.api.OpenstackNodeStore;
|
||||||
import org.onosproject.openstacknode.api.OpenstackNodeStoreDelegate;
|
import org.onosproject.openstacknode.api.OpenstackNodeStoreDelegate;
|
||||||
|
import org.onosproject.ovsdb.controller.OvsdbController;
|
||||||
|
import org.onosproject.store.service.StorageService;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.util.Dictionary;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -46,8 +57,11 @@ import java.util.stream.Collectors;
|
|||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
||||||
|
import static org.onlab.packet.TpPort.tpPort;
|
||||||
import static org.onlab.util.Tools.groupedThreads;
|
import static org.onlab.util.Tools.groupedThreads;
|
||||||
|
import static org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE;
|
||||||
import static org.onosproject.openstacknode.api.NodeState.COMPLETE;
|
import static org.onosproject.openstacknode.api.NodeState.COMPLETE;
|
||||||
|
import static org.onosproject.openstacknode.util.OpenstackNodeUtil.isOvsdbConnected;
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,6 +78,8 @@ public class OpenstackNodeManager extends ListenerRegistry<OpenstackNodeEvent, O
|
|||||||
private static final String MSG_CREATED = "created";
|
private static final String MSG_CREATED = "created";
|
||||||
private static final String MSG_UPDATED = "updated";
|
private static final String MSG_UPDATED = "updated";
|
||||||
private static final String MSG_REMOVED = "removed";
|
private static final String MSG_REMOVED = "removed";
|
||||||
|
private static final String OVSDB_PORT = "ovsdbPortNum";
|
||||||
|
private static final int DEFAULT_OVSDB_PORT = 6640;
|
||||||
|
|
||||||
private static final String ERR_NULL_NODE = "OpenStack node cannot be null";
|
private static final String ERR_NULL_NODE = "OpenStack node cannot be null";
|
||||||
private static final String ERR_NULL_HOSTNAME = "OpenStack node hostname cannot be null";
|
private static final String ERR_NULL_HOSTNAME = "OpenStack node hostname cannot be null";
|
||||||
@ -80,6 +96,19 @@ public class OpenstackNodeManager extends ListenerRegistry<OpenstackNodeEvent, O
|
|||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected LeadershipService leadershipService;
|
protected LeadershipService leadershipService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected StorageService storageService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected OvsdbController ovsdbController;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected DeviceService deviceService;
|
||||||
|
|
||||||
|
@Property(name = OVSDB_PORT, intValue = DEFAULT_OVSDB_PORT,
|
||||||
|
label = "OVSDB server listen port")
|
||||||
|
private int ovsdbPort = DEFAULT_OVSDB_PORT;
|
||||||
|
|
||||||
private final ExecutorService eventExecutor = newSingleThreadExecutor(
|
private final ExecutorService eventExecutor = newSingleThreadExecutor(
|
||||||
groupedThreads(this.getClass().getSimpleName(), "event-handler", log));
|
groupedThreads(this.getClass().getSimpleName(), "event-handler", log));
|
||||||
|
|
||||||
@ -107,6 +136,17 @@ public class OpenstackNodeManager extends ListenerRegistry<OpenstackNodeEvent, O
|
|||||||
log.info("Stopped");
|
log.info("Stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Modified
|
||||||
|
protected void modified(ComponentContext context) {
|
||||||
|
Dictionary<?, ?> properties = context.getProperties();
|
||||||
|
int updatedOvsdbPort = Tools.getIntegerProperty(properties, OVSDB_PORT);
|
||||||
|
if (!Objects.equals(updatedOvsdbPort, ovsdbPort)) {
|
||||||
|
ovsdbPort = updatedOvsdbPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("Modified");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createNode(OpenstackNode osNode) {
|
public void createNode(OpenstackNode osNode) {
|
||||||
checkNotNull(osNode, ERR_NULL_NODE);
|
checkNotNull(osNode, ERR_NULL_NODE);
|
||||||
@ -172,6 +212,57 @@ public class OpenstackNodeManager extends ListenerRegistry<OpenstackNodeEvent, O
|
|||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
log.trace("addVfPort called");
|
||||||
|
|
||||||
|
if (!isOvsdbConnected(osNode, ovsdbPort, ovsdbController, deviceService)) {
|
||||||
|
log.warn("There's no ovsdb connection with the device {}. Try to connect the device...",
|
||||||
|
osNode.ovsdb().toString());
|
||||||
|
try {
|
||||||
|
ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to connect to the openstackNode via ovsdb protocol because of exception {}",
|
||||||
|
e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, portName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
log.trace("removeVfPort called");
|
||||||
|
|
||||||
|
if (!isOvsdbConnected(osNode, ovsdbPort, ovsdbController, deviceService)) {
|
||||||
|
log.warn("There's no ovsdb connection with the device {}. Try to connect the device...",
|
||||||
|
osNode.ovsdb().toString());
|
||||||
|
try {
|
||||||
|
ovsdbController.connect(osNode.managementIp(), tpPort(ovsdbPort));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to connect to the openstackNode via ovsdb protocol because of exception {}",
|
||||||
|
e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addOrRemoveSystemInterface(osNode, INTEGRATION_BRIDGE, portName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addOrRemoveSystemInterface(OpenstackNode osNode, String bridgeName, String intfName,
|
||||||
|
boolean addOrRemove) {
|
||||||
|
Device device = deviceService.getDevice(osNode.ovsdb());
|
||||||
|
if (device == null || !device.is(BridgeConfig.class)) {
|
||||||
|
log.info("device is null or this device if not ovsdb device");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
|
||||||
|
if (addOrRemove) {
|
||||||
|
bridgeConfig.addPort(BridgeName.bridgeName(bridgeName), intfName);
|
||||||
|
} else {
|
||||||
|
bridgeConfig.deletePort(BridgeName.bridgeName(bridgeName), intfName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class InternalNodeStoreDelegate implements OpenstackNodeStoreDelegate {
|
private class InternalNodeStoreDelegate implements OpenstackNodeStoreDelegate {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.openstacknode.util;
|
||||||
|
|
||||||
|
import org.onosproject.net.device.DeviceService;
|
||||||
|
import org.onosproject.openstacknode.api.OpenstackNode;
|
||||||
|
import org.onosproject.ovsdb.controller.OvsdbClientService;
|
||||||
|
import org.onosproject.ovsdb.controller.OvsdbController;
|
||||||
|
import org.onosproject.ovsdb.controller.OvsdbNodeId;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An utility that used in openstack node app.
|
||||||
|
*/
|
||||||
|
public final class OpenstackNodeUtil {
|
||||||
|
protected static final Logger log = LoggerFactory.getLogger(OpenstackNodeUtil.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prevents object instantiation from external.
|
||||||
|
*/
|
||||||
|
private OpenstackNodeUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the controller has a connection with an OVSDB that resides
|
||||||
|
* inside the given openstack node.
|
||||||
|
*
|
||||||
|
* @param osNode openstack node
|
||||||
|
* @param ovsdbPort ovsdb port
|
||||||
|
* @param ovsdbController ovsdb controller
|
||||||
|
* @param deviceService device service
|
||||||
|
* @return true if the controller is connected to the OVSDB, false otherwise
|
||||||
|
*/
|
||||||
|
public static boolean isOvsdbConnected(OpenstackNode osNode,
|
||||||
|
int ovsdbPort,
|
||||||
|
OvsdbController ovsdbController,
|
||||||
|
DeviceService deviceService) {
|
||||||
|
OvsdbNodeId ovsdb = new OvsdbNodeId(osNode.managementIp(), ovsdbPort);
|
||||||
|
OvsdbClientService client = ovsdbController.getOvsdbClient(ovsdb);
|
||||||
|
return deviceService.isAvailable(osNode.ovsdb()) &&
|
||||||
|
client != null &&
|
||||||
|
client.isConnected();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present Open Networking Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Openstack node utility package.
|
||||||
|
*/
|
||||||
|
package org.onosproject.openstacknode.util;
|
@ -119,6 +119,7 @@ public class OpenstackNodeManagerTest extends OpenstackNodeTest {
|
|||||||
osNodeStore.createNode(GATEWAY_1);
|
osNodeStore.createNode(GATEWAY_1);
|
||||||
|
|
||||||
target = new org.onosproject.openstacknode.impl.OpenstackNodeManager();
|
target = new org.onosproject.openstacknode.impl.OpenstackNodeManager();
|
||||||
|
target.storageService = new TestStorageService();
|
||||||
target.coreService = new TestCoreService();
|
target.coreService = new TestCoreService();
|
||||||
target.clusterService = new TestClusterService();
|
target.clusterService = new TestClusterService();
|
||||||
target.leadershipService = new TestLeadershipService();
|
target.leadershipService = new TestLeadershipService();
|
||||||
|
@ -76,6 +76,15 @@ public class TestOpenstackNodeManager implements OpenstackNodeService, Openstack
|
|||||||
.filter(osNode -> Objects.equals(osNode.intgBridge(), deviceId) ||
|
.filter(osNode -> Objects.equals(osNode.intgBridge(), deviceId) ||
|
||||||
Objects.equals(osNode.ovsdb(), deviceId))
|
Objects.equals(osNode.ovsdb(), deviceId))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeVfPort(OpenstackNode osNode, String portName) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user