diff options
author | CNlucius <lukai1@huawei.com> | 2016-09-13 11:40:12 +0800 |
---|---|---|
committer | CNlucius <lukai1@huawei.com> | 2016-09-13 11:41:53 +0800 |
commit | b731e2f1dd0972409b136aebc7b463dd72c9cfad (patch) | |
tree | 5107d7d80c19ad8076c2c97c2b5ef8d1cf3ab903 /framework/src/onos/apps/cordvtn/src/main/java/org | |
parent | ee93993458266114c29271a481ef9ce7ce621b2a (diff) |
ONOSFW-171
O/S-SFC-ONOS scenario documentation
Change-Id: I51ae1cf736ea24ab6680f8edca1b2bf5dd598365
Signed-off-by: CNlucius <lukai1@huawei.com>
Diffstat (limited to 'framework/src/onos/apps/cordvtn/src/main/java/org')
14 files changed, 0 insertions, 2111 deletions
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/ConnectionHandler.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/ConnectionHandler.java deleted file mode 100644 index af738230..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/ConnectionHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -/** - * Entity capable of handling a subject connected and disconnected situation. - */ -public interface ConnectionHandler<T> { - - /** - * Processes the connected subject. - * - * @param subject subject - */ - void connected(T subject); - - /** - * Processes the disconnected subject. - * - * @param subject subject. - */ - void disconnected(T subject); -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java deleted file mode 100644 index 67297741..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java +++ /dev/null @@ -1,926 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -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.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.util.ItemNotFoundException; -import org.onlab.packet.IpAddress; -import org.onlab.util.KryoNamespace; -import org.onosproject.cluster.ClusterService; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Host; -import org.onosproject.net.HostId; -import org.onosproject.net.Port; -import org.onosproject.net.behaviour.BridgeConfig; -import org.onosproject.net.behaviour.BridgeName; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.behaviour.ControllerInfo; -import org.onosproject.net.behaviour.DefaultTunnelDescription; -import org.onosproject.net.behaviour.TunnelConfig; -import org.onosproject.net.behaviour.TunnelDescription; -import org.onosproject.net.behaviour.TunnelName; -import org.onosproject.net.device.DeviceAdminService; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.net.driver.DriverService; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.host.HostEvent; -import org.onosproject.net.host.HostListener; -import org.onosproject.net.host.HostService; -import org.onosproject.openstackswitching.OpenstackNetwork; -import org.onosproject.openstackswitching.OpenstackPort; -import org.onosproject.openstackswitching.OpenstackSwitchingService; -import org.onosproject.ovsdb.controller.OvsdbClientService; -import org.onosproject.ovsdb.controller.OvsdbController; -import org.onosproject.ovsdb.controller.OvsdbNodeId; -import org.onosproject.store.serializers.KryoNamespaces; -import org.onosproject.store.service.ConsistentMap; -import org.onosproject.store.service.Serializer; -import org.onosproject.store.service.StorageService; -import org.slf4j.Logger; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.stream.Collectors; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onlab.util.Tools.groupedThreads; -import static org.onosproject.net.Device.Type.SWITCH; -import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Provisions virtual tenant networks with service chaining capability - * in OpenStack environment. - */ -@Component(immediate = true) -@Service -public class CordVtn implements CordVtnService { - - protected final Logger log = getLogger(getClass()); - - private static final int NUM_THREADS = 1; - private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder() - .register(KryoNamespaces.API) - .register(CordVtnNode.class) - .register(NodeState.class); - private static final String DEFAULT_BRIDGE = "br-int"; - private static final String VPORT_PREFIX = "tap"; - private static final String DEFAULT_TUNNEL = "vxlan"; - private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() { - { - put("key", "flow"); - put("remote_ip", "flow"); - } - }; - private static final int DPID_BEGIN = 3; - private static final int OFPORT = 6653; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected StorageService storageService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostService hostService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DriverService driverService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceAdminService adminService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveService flowObjectiveService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected OvsdbController controller; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterService clusterService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected OpenstackSwitchingService openstackService; - - private final ExecutorService eventExecutor = Executors - .newFixedThreadPool(NUM_THREADS, groupedThreads("onos/cordvtn", "event-handler")); - - private final DeviceListener deviceListener = new InternalDeviceListener(); - private final HostListener hostListener = new InternalHostListener(); - - private final OvsdbHandler ovsdbHandler = new OvsdbHandler(); - private final BridgeHandler bridgeHandler = new BridgeHandler(); - private final VmHandler vmHandler = new VmHandler(); - - private ConsistentMap<CordVtnNode, NodeState> nodeStore; - private Map<HostId, String> hostNetworkMap = Maps.newHashMap(); - private CordVtnRuleInstaller ruleInstaller; - - private enum NodeState { - - INIT { - @Override - public void process(CordVtn cordVtn, CordVtnNode node) { - cordVtn.connect(node); - } - }, - OVSDB_CONNECTED { - @Override - public void process(CordVtn cordVtn, CordVtnNode node) { - if (!cordVtn.getOvsdbConnectionState(node)) { - cordVtn.connect(node); - } else { - cordVtn.createIntegrationBridge(node); - } - } - }, - BRIDGE_CREATED { - @Override - public void process(CordVtn cordVtn, CordVtnNode node) { - if (!cordVtn.getOvsdbConnectionState(node)) { - cordVtn.connect(node); - } else { - cordVtn.createTunnelInterface(node); - } - } - }, - COMPLETE { - @Override - public void process(CordVtn cordVtn, CordVtnNode node) { - cordVtn.postInit(node); - } - }, - INCOMPLETE { - @Override - public void process(CordVtn cordVtn, CordVtnNode node) { - } - }; - - public abstract void process(CordVtn cordVtn, CordVtnNode node); - } - - @Activate - protected void activate() { - ApplicationId appId = coreService.registerApplication("org.onosproject.cordvtn"); - nodeStore = storageService.<CordVtnNode, NodeState>consistentMapBuilder() - .withSerializer(Serializer.using(NODE_SERIALIZER.build())) - .withName("cordvtn-nodestore") - .withApplicationId(appId) - .build(); - - ruleInstaller = new CordVtnRuleInstaller(appId, flowObjectiveService, - driverService, DEFAULT_TUNNEL); - deviceService.addListener(deviceListener); - hostService.addListener(hostListener); - - log.info("Started"); - } - - @Deactivate - protected void deactivate() { - deviceService.removeListener(deviceListener); - hostService.removeListener(hostListener); - - eventExecutor.shutdown(); - nodeStore.clear(); - - log.info("Stopped"); - } - - @Override - public void addNode(CordVtnNode node) { - checkNotNull(node); - - nodeStore.putIfAbsent(node, checkNodeState(node)); - initNode(node); - } - - @Override - public void deleteNode(CordVtnNode node) { - checkNotNull(node); - - if (getOvsdbConnectionState(node)) { - disconnect(node); - } - - nodeStore.remove(node); - } - - @Override - public int getNodeCount() { - return nodeStore.size(); - } - - @Override - public List<CordVtnNode> getNodes() { - List<CordVtnNode> nodes = new ArrayList<>(); - nodes.addAll(nodeStore.keySet()); - return nodes; - } - - @Override - public void initNode(CordVtnNode node) { - checkNotNull(node); - - if (!nodeStore.containsKey(node)) { - log.warn("Node {} does not exist, add node first", node.hostname()); - return; - } - - NodeState state = getNodeState(node); - if (state == null) { - return; - } else if (state.equals(NodeState.INCOMPLETE)) { - state = checkNodeState(node); - } - - state.process(this, node); - } - - @Override - public boolean getNodeInitState(CordVtnNode node) { - checkNotNull(node); - - NodeState state = getNodeState(node); - return state != null && state.equals(NodeState.COMPLETE); - } - - /** - * Returns state of a given cordvtn node. - * - * @param node cordvtn node - * @return node state, or null if no such node exists - */ - private NodeState getNodeState(CordVtnNode node) { - checkNotNull(node); - - try { - return nodeStore.get(node).value(); - } catch (NullPointerException e) { - log.error("Failed to get state of {}", node.hostname()); - return null; - } - } - - /** - * Sets a new state for a given cordvtn node. - * - * @param node cordvtn node - * @param newState new node state - */ - private void setNodeState(CordVtnNode node, NodeState newState) { - checkNotNull(node); - - log.info("Changed {} state: {}", node.hostname(), newState.toString()); - - nodeStore.put(node, newState); - newState.process(this, node); - } - - /** - * Checks current state of a given cordvtn node and returns it. - * - * @param node cordvtn node - * @return node state - */ - private NodeState checkNodeState(CordVtnNode node) { - checkNotNull(node); - - if (checkIntegrationBridge(node) && checkTunnelInterface(node)) { - return NodeState.COMPLETE; - } else if (checkIntegrationBridge(node)) { - return NodeState.BRIDGE_CREATED; - } else if (getOvsdbConnectionState(node)) { - return NodeState.OVSDB_CONNECTED; - } else { - return NodeState.INIT; - } - } - - /** - * Performs tasks after node initialization. - * First disconnect unnecessary OVSDB connection and then installs flow rules - * for existing VMs if there are any. - * - * @param node cordvtn node - */ - private void postInit(CordVtnNode node) { - disconnect(node); - - Set<OpenstackNetwork> vNets = Sets.newHashSet(); - hostService.getConnectedHosts(node.intBrId()) - .stream() - .forEach(host -> { - OpenstackNetwork vNet = getOpenstackNetworkByHost(host); - if (vNet != null) { - log.info("VM {} is detected", host.id()); - - hostNetworkMap.put(host.id(), vNet.id()); - vNets.add(vNet); - } - }); - vNets.stream().forEach(this::installFlowRules); - } - - /** - * Returns connection state of OVSDB server for a given node. - * - * @param node cordvtn node - * @return true if it is connected, false otherwise - */ - private boolean getOvsdbConnectionState(CordVtnNode node) { - checkNotNull(node); - - OvsdbClientService ovsdbClient = getOvsdbClient(node); - return deviceService.isAvailable(node.ovsdbId()) && - ovsdbClient != null && ovsdbClient.isConnected(); - } - - /** - * Connects to OVSDB server for a given node. - * - * @param node cordvtn node - */ - private void connect(CordVtnNode node) { - checkNotNull(node); - - if (!nodeStore.containsKey(node)) { - log.warn("Node {} does not exist", node.hostname()); - return; - } - - if (!getOvsdbConnectionState(node)) { - // FIXME remove existing OVSDB device to work around OVSDB device re-connect issue - if (deviceService.getDevice(node.ovsdbId()) != null) { - adminService.removeDevice(node.ovsdbId()); - } - controller.connect(node.ovsdbIp(), node.ovsdbPort()); - } - } - - /** - * Disconnects OVSDB server for a given node. - * - * @param node cordvtn node - */ - private void disconnect(CordVtnNode node) { - checkNotNull(node); - - if (!nodeStore.containsKey(node)) { - log.warn("Node {} does not exist", node.hostname()); - return; - } - - if (getOvsdbConnectionState(node)) { - OvsdbClientService ovsdbClient = getOvsdbClient(node); - ovsdbClient.disconnect(); - } - - // FIXME remove existing OVSDB device to work around OVSDB device re-connect issue - if (deviceService.getDevice(node.ovsdbId()) != null) { - adminService.removeDevice(node.ovsdbId()); - } - } - - /** - * Returns cordvtn node associated with a given OVSDB device. - * - * @param ovsdbId OVSDB device id - * @return cordvtn node, null if it fails to find the node - */ - private CordVtnNode getNodeByOvsdbId(DeviceId ovsdbId) { - try { - return getNodes().stream() - .filter(node -> node.ovsdbId().equals(ovsdbId)) - .findFirst().get(); - } catch (NoSuchElementException e) { - log.debug("Couldn't find node information for {}", ovsdbId); - return null; - } - } - - /** - * Returns cordvtn node associated with a given integration bridge. - * - * @param bridgeId device id of integration bridge - * @return cordvtn node, null if it fails to find the node - */ - private CordVtnNode getNodeByBridgeId(DeviceId bridgeId) { - try { - return getNodes().stream() - .filter(node -> node.intBrId().equals(bridgeId)) - .findFirst().get(); - } catch (NoSuchElementException e) { - log.debug("Couldn't find node information for {}", bridgeId); - return null; - } - } - - /** - * Returns OVSDB client for a given node. - * - * @param node cordvtn node - * @return OVSDB client, or null if it fails to get OVSDB client - */ - private OvsdbClientService getOvsdbClient(CordVtnNode node) { - checkNotNull(node); - - OvsdbClientService ovsdbClient = controller.getOvsdbClient( - new OvsdbNodeId(node.ovsdbIp(), node.ovsdbPort().toInt())); - if (ovsdbClient == null) { - log.debug("Couldn't find OVSDB client for {}", node.hostname()); - } - return ovsdbClient; - } - - /** - * Creates an integration bridge for a given node. - * - * @param node cordvtn node - */ - private void createIntegrationBridge(CordVtnNode node) { - if (checkIntegrationBridge(node)) { - return; - } - - List<ControllerInfo> controllers = new ArrayList<>(); - Sets.newHashSet(clusterService.getNodes()).stream() - .forEach(controller -> { - ControllerInfo ctrlInfo = new ControllerInfo(controller.ip(), OFPORT, "tcp"); - controllers.add(ctrlInfo); - }); - String dpid = node.intBrId().toString().substring(DPID_BEGIN); - - try { - DriverHandler handler = driverService.createHandler(node.ovsdbId()); - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE), dpid, controllers); - } catch (ItemNotFoundException e) { - log.warn("Failed to create integration bridge on {}", node.ovsdbId()); - } - } - - /** - * Creates tunnel interface to the integration bridge for a given node. - * - * @param node cordvtn node - */ - private void createTunnelInterface(CordVtnNode node) { - if (checkTunnelInterface(node)) { - return; - } - - DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder(); - for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) { - optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key)); - } - TunnelDescription description = - new DefaultTunnelDescription(null, null, VXLAN, TunnelName.tunnelName(DEFAULT_TUNNEL), - optionBuilder.build()); - try { - DriverHandler handler = driverService.createHandler(node.ovsdbId()); - TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); - tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE), description); - } catch (ItemNotFoundException e) { - log.warn("Failed to create tunnel interface on {}", node.ovsdbId()); - } - } - - /** - * Checks if integration bridge exists and available. - * - * @param node cordvtn node - * @return true if the bridge is available, false otherwise - */ - private boolean checkIntegrationBridge(CordVtnNode node) { - return (deviceService.getDevice(node.intBrId()) != null - && deviceService.isAvailable(node.intBrId())); - } - - /** - * Checks if tunnel interface exists. - * - * @param node cordvtn node - * @return true if the interface exists, false otherwise - */ - private boolean checkTunnelInterface(CordVtnNode node) { - try { - deviceService.getPorts(node.intBrId()) - .stream() - .filter(p -> p.annotations().value("portName").contains(DEFAULT_TUNNEL) - && p.isEnabled()) - .findAny().get(); - return true; - } catch (NoSuchElementException e) { - return false; - } - } - - /** - * Returns tunnel port of the device. - * - * @param bridgeId device id - * @return port, null if no tunnel port exists on a given device - */ - private Port getTunnelPort(DeviceId bridgeId) { - try { - return deviceService.getPorts(bridgeId).stream() - .filter(p -> p.annotations().value("portName").contains(DEFAULT_TUNNEL) - && p.isEnabled()) - .findFirst().get(); - } catch (NoSuchElementException e) { - return null; - } - } - - /** - * Returns remote ip address for tunneling. - * - * @param bridgeId device id - * @return ip address, null if no such device exists - */ - private IpAddress getRemoteIp(DeviceId bridgeId) { - CordVtnNode node = getNodeByBridgeId(bridgeId); - if (node != null) { - // TODO get data plane IP for tunneling - return node.ovsdbIp(); - } else { - return null; - } - } - - /** - * Returns destination information of all ports associated with a given - * OpenStack network. Output of the destination information is set to local - * port or tunnel port according to a given device id. - * - * @param deviceId device id to install flow rules - * @param vNet OpenStack network - * @return list of flow information, empty list if no flow information exists - */ - private List<DestinationInfo> getSameNetworkPortsInfo(DeviceId deviceId, OpenstackNetwork vNet) { - List<DestinationInfo> dstInfos = Lists.newArrayList(); - long tunnelId = Long.valueOf(vNet.segmentId()); - - for (OpenstackPort vPort : openstackService.ports(vNet.id())) { - ConnectPoint cp = getConnectPoint(vPort); - if (cp == null) { - log.debug("Couldn't find connection point for OpenStack port {}", vPort.id()); - continue; - } - - DestinationInfo.Builder dBuilder = cp.deviceId().equals(deviceId) ? - DestinationInfo.builder(deviceService.getPort(cp.deviceId(), cp.port())) : - DestinationInfo.builder(getTunnelPort(deviceId)) - .setRemoteIp(getRemoteIp(cp.deviceId())); - - dBuilder.setMac(vPort.macAddress()) - .setTunnelId(tunnelId); - dstInfos.add(dBuilder.build()); - } - return dstInfos; - } - - /** - * Returns local ports associated with a given OpenStack network. - * - * @param bridgeId device id - * @param vNet OpenStack network - * @return port list, empty list if no port exists - */ - private List<Port> getLocalSameNetworkPorts(DeviceId bridgeId, OpenstackNetwork vNet) { - List<Port> ports = new ArrayList<>(); - openstackService.ports(vNet.id()).stream().forEach(port -> { - ConnectPoint cp = getConnectPoint(port); - if (cp != null && cp.deviceId().equals(bridgeId)) { - ports.add(deviceService.getPort(cp.deviceId(), cp.port())); - } - }); - return ports; - } - - /** - * Returns OpenStack port associated with a given host. - * - * @param host host - * @return OpenStack port, or null if no port has been found - */ - private OpenstackPort getOpenstackPortByHost(Host host) { - Port port = deviceService.getPort(host.location().deviceId(), - host.location().port()); - return openstackService.port(port); - } - - /** - * Returns OpenStack network associated with a given host. - * - * @param host host - * @return OpenStack network, or null if no network has been found - */ - private OpenstackNetwork getOpenstackNetworkByHost(Host host) { - OpenstackPort vPort = getOpenstackPortByHost(host); - if (vPort != null) { - return openstackService.network(vPort.networkId()); - } else { - return null; - } - } - - /** - * Returns port name with OpenStack port information. - * - * @param vPort OpenStack port - * @return port name - */ - private String getPortName(OpenstackPort vPort) { - checkNotNull(vPort); - return VPORT_PREFIX + vPort.id().substring(0, 10); - } - - /** - * Returns connect point of a given OpenStack port. - * It assumes there's only one physical port associated with an OpenStack port. - * - * @param vPort openstack port - * @return connect point, null if no such port exists - */ - private ConnectPoint getConnectPoint(OpenstackPort vPort) { - try { - Host host = hostService.getHostsByMac(vPort.macAddress()) - .stream() - .findFirst() - .get(); - return new ConnectPoint(host.location().deviceId(), host.location().port()); - } catch (NoSuchElementException e) { - log.debug("Not a valid host with {}", vPort.macAddress()); - return null; - } - } - - /** - * Installs flow rules for a given OpenStack network. - * - * @param vNet OpenStack network - */ - private void installFlowRules(OpenstackNetwork vNet) { - checkNotNull(vNet, "Tenant network should not be null"); - - for (Device device : deviceService.getAvailableDevices(SWITCH)) { - List<DestinationInfo> dstInfos = getSameNetworkPortsInfo(device.id(), vNet); - - for (Port inPort : getLocalSameNetworkPorts(device.id(), vNet)) { - List<DestinationInfo> localInInfos = dstInfos.stream() - .filter(info -> !info.output().equals(inPort)) - .collect(Collectors.toList()); - ruleInstaller.installFlowRulesLocalIn(device.id(), inPort, localInInfos); - } - - Port tunPort = getTunnelPort(device.id()); - List<DestinationInfo> tunnelInInfos = dstInfos.stream() - .filter(info -> !info.output().equals(tunPort)) - .collect(Collectors.toList()); - ruleInstaller.installFlowRulesTunnelIn(device.id(), tunPort, tunnelInInfos); - } - } - - /** - * Uninstalls flow rules associated with a given host for a given OpenStack network. - * - * @param vNet OpenStack network - * @param host removed host - */ - private void uninstallFlowRules(OpenstackNetwork vNet, Host host) { - checkNotNull(vNet, "Tenant network should not be null"); - - Port removedPort = deviceService.getPort(host.location().deviceId(), - host.location().port()); - - for (Device device : deviceService.getAvailableDevices(SWITCH)) { - List<DestinationInfo> dstInfos = getSameNetworkPortsInfo(device.id(), vNet); - - for (Port inPort : getLocalSameNetworkPorts(device.id(), vNet)) { - List<DestinationInfo> localInInfos = Lists.newArrayList( - DestinationInfo.builder(getTunnelPort(device.id())) - .setTunnelId(Long.valueOf(vNet.segmentId())) - .setMac(host.mac()) - .setRemoteIp(getRemoteIp(host.location().deviceId())) - .build()); - ruleInstaller.uninstallFlowRules(device.id(), inPort, localInInfos); - } - - if (device.id().equals(host.location().deviceId())) { - Port tunPort = getTunnelPort(device.id()); - List<DestinationInfo> tunnelInInfo = Lists.newArrayList( - DestinationInfo.builder(removedPort) - .setTunnelId(Long.valueOf(vNet.segmentId())) - .setMac(host.mac()) - .build()); - - ruleInstaller.uninstallFlowRules(device.id(), tunPort, tunnelInInfo); - ruleInstaller.uninstallFlowRules(device.id(), removedPort, dstInfos); - } - } - } - - private class InternalDeviceListener implements DeviceListener { - - @Override - public void event(DeviceEvent event) { - - Device device = event.subject(); - ConnectionHandler<Device> handler = - (device.type().equals(SWITCH) ? bridgeHandler : ovsdbHandler); - - switch (event.type()) { - case PORT_ADDED: - eventExecutor.submit(() -> bridgeHandler.portAdded(event.port())); - break; - case PORT_UPDATED: - if (!event.port().isEnabled()) { - eventExecutor.submit(() -> bridgeHandler.portRemoved(event.port())); - } - break; - case DEVICE_ADDED: - case DEVICE_AVAILABILITY_CHANGED: - if (deviceService.isAvailable(device.id())) { - eventExecutor.submit(() -> handler.connected(device)); - } else { - eventExecutor.submit(() -> handler.disconnected(device)); - } - break; - default: - break; - } - } - } - - private class InternalHostListener implements HostListener { - - @Override - public void event(HostEvent event) { - Host vm = event.subject(); - - switch (event.type()) { - case HOST_ADDED: - eventExecutor.submit(() -> vmHandler.connected(vm)); - break; - case HOST_REMOVED: - eventExecutor.submit(() -> vmHandler.disconnected(vm)); - break; - default: - break; - } - } - } - - private class OvsdbHandler implements ConnectionHandler<Device> { - - @Override - public void connected(Device device) { - CordVtnNode node = getNodeByOvsdbId(device.id()); - if (node != null) { - setNodeState(node, checkNodeState(node)); - } - } - - @Override - public void disconnected(Device device) { - log.info("OVSDB {} is disconnected", device.id()); - } - } - - private class BridgeHandler implements ConnectionHandler<Device> { - - @Override - public void connected(Device device) { - CordVtnNode node = getNodeByBridgeId(device.id()); - if (node != null) { - setNodeState(node, checkNodeState(node)); - } - } - - @Override - public void disconnected(Device device) { - CordVtnNode node = getNodeByBridgeId(device.id()); - if (node != null) { - log.info("Integration Bridge is disconnected from {}", node.hostname()); - setNodeState(node, NodeState.INCOMPLETE); - } - } - - /** - * Handles port added situation. - * If the added port is tunnel port, proceed remaining node initialization. - * Otherwise, do nothing. - * - * @param port port - */ - public void portAdded(Port port) { - if (!port.annotations().value("portName").contains(DEFAULT_TUNNEL)) { - return; - } - - CordVtnNode node = getNodeByBridgeId((DeviceId) port.element().id()); - if (node != null) { - setNodeState(node, checkNodeState(node)); - } - } - - /** - * Handles port removed situation. - * If the removed port is tunnel port, proceed remaining node initialization. - * Others, do nothing. - * - * @param port port - */ - public void portRemoved(Port port) { - if (!port.annotations().value("portName").contains(DEFAULT_TUNNEL)) { - return; - } - - CordVtnNode node = getNodeByBridgeId((DeviceId) port.element().id()); - if (node != null) { - log.info("Tunnel interface is removed from {}", node.hostname()); - setNodeState(node, NodeState.INCOMPLETE); - } - } - } - - private class VmHandler implements ConnectionHandler<Host> { - - @Override - public void connected(Host host) { - CordVtnNode node = getNodeByBridgeId(host.location().deviceId()); - if (node == null || !getNodeState(node).equals(NodeState.COMPLETE)) { - // do nothing for the host on unregistered or unprepared device - return; - } - - OpenstackNetwork vNet = getOpenstackNetworkByHost(host); - if (vNet == null) { - return; - } - - log.info("VM {} is detected", host.id()); - - hostNetworkMap.put(host.id(), vNet.id()); - installFlowRules(vNet); - } - - @Override - public void disconnected(Host host) { - CordVtnNode node = getNodeByBridgeId(host.location().deviceId()); - if (node == null || !getNodeState(node).equals(NodeState.COMPLETE)) { - // do nothing for the host on unregistered or unprepared device - return; - } - - OpenstackNetwork vNet = openstackService.network(hostNetworkMap.get(host.id())); - if (vNet == null) { - return; - } - - log.info("VM {} is vanished", host.id()); - - uninstallFlowRules(vNet, host); - hostNetworkMap.remove(host.id()); - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java deleted file mode 100644 index 827ce052..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -import com.fasterxml.jackson.databind.JsonNode; -import com.google.common.collect.Sets; -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.DeviceId; -import org.onosproject.net.config.Config; - -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Configuration object for CordVtn service. - */ -public class CordVtnConfig extends Config<ApplicationId> { - - public static final String CORDVTN_NODES = "nodes"; - public static final String HOSTNAME = "hostname"; - public static final String OVSDB_IP = "ovsdbIp"; - public static final String OVSDB_PORT = "ovsdbPort"; - public static final String BRIDGE_ID = "bridgeId"; - - /** - * Returns the set of nodes read from network config. - * - * @return set of CordVtnNodeConfig or null - */ - public Set<CordVtnNodeConfig> cordVtnNodes() { - Set<CordVtnNodeConfig> nodes = Sets.newHashSet(); - - JsonNode jsonNodes = object.get(CORDVTN_NODES); - if (jsonNodes == null) { - return null; - } - jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig( - jsonNode.path(HOSTNAME).asText(), - IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()), - TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()), - DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())))); - - return nodes; - } - - /** - * Configuration for CordVtn node. - */ - public static class CordVtnNodeConfig { - - private final String hostname; - private final IpAddress ovsdbIp; - private final TpPort ovsdbPort; - private final DeviceId bridgeId; - - public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId) { - this.hostname = checkNotNull(hostname); - this.ovsdbIp = checkNotNull(ovsdbIp); - this.ovsdbPort = checkNotNull(ovsdbPort); - this.bridgeId = checkNotNull(bridgeId); - } - - /** - * Returns hostname of the node. - * - * @return hostname - */ - public String hostname() { - return this.hostname; - } - - /** - * Returns OVSDB ip address of the node. - * - * @return OVSDB server IP address - */ - public IpAddress ovsdbIp() { - return this.ovsdbIp; - } - - /** - * Returns OVSDB port number of the node. - * - * @return port number - */ - public TpPort ovsdbPort() { - return this.ovsdbPort; - } - - /** - * Returns integration bridge id of the node. - * - * @return device id - */ - public DeviceId bridgeId() { - return this.bridgeId; - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java deleted file mode 100644 index f79b4460..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -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.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.config.ConfigFactory; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.net.config.basics.SubjectFactories; -import org.slf4j.Logger; - -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Reads node information from the network config file and handles the config - * update events. - * Only a leader controller performs the node addition or deletion. - */ -@Component(immediate = true) -public class CordVtnConfigManager { - - protected final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry configRegistry; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigService configService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CordVtnService cordVtnService; - - private final ConfigFactory configFactory = - new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, CordVtnConfig.class, "cordvtn") { - @Override - public CordVtnConfig createConfig() { - return new CordVtnConfig(); - } - }; - - private final NetworkConfigListener configListener = new InternalConfigListener(); - - private ApplicationId appId; - - @Activate - protected void active() { - appId = coreService.getAppId(CordVtnService.CORDVTN_APP_ID); - - configService.addListener(configListener); - configRegistry.registerConfigFactory(configFactory); - } - - @Deactivate - protected void deactivate() { - configRegistry.unregisterConfigFactory(configFactory); - configService.removeListener(configListener); - } - - private void readConfiguration() { - CordVtnConfig config = configRegistry.getConfig(appId, CordVtnConfig.class); - - if (config == null) { - log.warn("No configuration found"); - return; - } - - config.cordVtnNodes().forEach(node -> { - CordVtnNode cordVtnNode = new CordVtnNode( - node.hostname(), node.ovsdbIp(), node.ovsdbPort(), node.bridgeId()); - cordVtnService.addNode(cordVtnNode); - }); - } - - private class InternalConfigListener implements NetworkConfigListener { - - @Override - public void event(NetworkConfigEvent event) { - if (!event.configClass().equals(CordVtnConfig.class)) { - return; - } - - switch (event.type()) { - case CONFIG_ADDED: - log.info("Network configuration added"); - readConfiguration(); - break; - case CONFIG_UPDATED: - log.info("Network configuration updated"); - readConfiguration(); - break; - default: - break; - } - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnNode.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnNode.java deleted file mode 100644 index 439d16e1..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnNode.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -import com.google.common.base.MoreObjects; -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.net.DeviceId; - -import java.util.Comparator; -import java.util.Objects; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Representation of a compute infrastructure node for CORD VTN service. - */ -public final class CordVtnNode { - - private final String hostname; - private final IpAddress ovsdbIp; - private final TpPort ovsdbPort; - private final DeviceId bridgeId; - - public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR = - (node1, node2) -> node1.hostname().compareTo(node2.hostname()); - - /** - * Creates a new node. - * - * @param hostname hostname - * @param ovsdbIp OVSDB server IP address - * @param ovsdbPort OVSDB server port number - * @param bridgeId integration bridge identifier - */ - public CordVtnNode(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId) { - this.hostname = checkNotNull(hostname); - this.ovsdbIp = checkNotNull(ovsdbIp); - this.ovsdbPort = checkNotNull(ovsdbPort); - this.bridgeId = checkNotNull(bridgeId); - } - - /** - * Returns the OVSDB server IP address. - * - * @return ip address - */ - public IpAddress ovsdbIp() { - return this.ovsdbIp; - } - - /** - * Returns the OVSDB server port number. - * - * @return port number - */ - public TpPort ovsdbPort() { - return this.ovsdbPort; - } - - /** - * Returns the hostname. - * - * @return hostname - */ - public String hostname() { - return this.hostname; - } - - /** - * Returns the identifier of the integration bridge. - * - * @return device id - */ - public DeviceId intBrId() { - return this.bridgeId; - } - - /** - * Returns the identifier of the OVSDB device. - * - * @return device id - */ - public DeviceId ovsdbId() { - return DeviceId.deviceId("ovsdb:" + this.ovsdbIp.toString()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj instanceof CordVtnNode) { - CordVtnNode that = (CordVtnNode) obj; - if (Objects.equals(hostname, that.hostname) && - Objects.equals(ovsdbIp, that.ovsdbIp) && - Objects.equals(ovsdbPort, that.ovsdbPort) && - Objects.equals(bridgeId, that.bridgeId)) { - return true; - } - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(hostname, ovsdbIp, ovsdbPort); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("host", hostname) - .add("ip", ovsdbIp) - .add("port", ovsdbPort) - .add("bridgeId", bridgeId) - .toString(); - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java deleted file mode 100644 index 9e22997c..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnRuleInstaller.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.cordvtn; - -import org.onlab.packet.Ip4Address; -import org.onlab.util.ItemNotFoundException; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Port; -import org.onosproject.net.behaviour.ExtensionTreatmentResolver; -import org.onosproject.net.driver.DefaultDriverData; -import org.onosproject.net.driver.DefaultDriverHandler; -import org.onosproject.net.driver.Driver; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.net.driver.DriverService; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.instructions.ExtensionPropertyException; -import org.onosproject.net.flow.instructions.ExtensionTreatment; -import org.onosproject.net.flowobjective.DefaultForwardingObjective; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.slf4j.Logger; - -import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Populates rules for virtual tenant network. - */ -public final class CordVtnRuleInstaller { - protected final Logger log = getLogger(getClass()); - - private static final int DEFAULT_PRIORITY = 5000; - - private final ApplicationId appId; - private final FlowObjectiveService flowObjectiveService; - private final DriverService driverService; - private final String tunnelType; - - /** - * Creates a new rule installer. - * - * @param appId application id - * @param flowObjectiveService flow objective service - * @param driverService driver service - * @param tunnelType tunnel type - */ - public CordVtnRuleInstaller(ApplicationId appId, - FlowObjectiveService flowObjectiveService, - DriverService driverService, - String tunnelType) { - this.appId = appId; - this.flowObjectiveService = flowObjectiveService; - this.driverService = driverService; - this.tunnelType = checkNotNull(tunnelType); - } - - /** - * Installs flow rules for tunnel in traffic. - * - * @param deviceId device id to install flow rules - * @param inPort in port - * @param dstInfos list of destination info - */ - public void installFlowRulesTunnelIn(DeviceId deviceId, Port inPort, List<DestinationInfo> dstInfos) { - dstInfos.stream().forEach(dstInfo -> { - ForwardingObjective.Builder fBuilder = vtnRulesSameNode(inPort, dstInfo); - if (fBuilder != null) { - flowObjectiveService.forward(deviceId, fBuilder.add()); - } - }); - } - - /** - * Installs flow rules for local in traffic. - * - * @param deviceId device id to install flow rules - * @param inPort in port - * @param dstInfos list of destination info - */ - public void installFlowRulesLocalIn(DeviceId deviceId, Port inPort, List<DestinationInfo> dstInfos) { - dstInfos.stream().forEach(dstInfo -> { - ForwardingObjective.Builder fBuilder = isTunnelPort(dstInfo.output()) ? - vtnRulesRemoteNode(deviceId, inPort, dstInfo) : vtnRulesSameNode(inPort, dstInfo); - - if (fBuilder != null) { - flowObjectiveService.forward(deviceId, fBuilder.add()); - } - }); - } - - /** - * Uninstalls flow rules associated with a given port from a given device. - * - * @param deviceId device id - * @param inPort port associated with removed host - * @param dstInfos list of destination info - */ - public void uninstallFlowRules(DeviceId deviceId, Port inPort, List<DestinationInfo> dstInfos) { - dstInfos.stream().forEach(dstInfo -> { - ForwardingObjective.Builder fBuilder = isTunnelPort(dstInfo.output()) ? - vtnRulesRemoteNode(deviceId, inPort, dstInfo) : vtnRulesSameNode(inPort, dstInfo); - - if (fBuilder != null) { - flowObjectiveService.forward(deviceId, fBuilder.remove()); - } - }); - } - - /** - * Returns forwarding objective builder to provision basic virtual tenant network. - * This method cares for the traffics whose source and destination device is the same. - * - * @param inPort in port - * @param dstInfo destination information - * @return forwarding objective builder - */ - private ForwardingObjective.Builder vtnRulesSameNode(Port inPort, DestinationInfo dstInfo) { - checkArgument(inPort.element().id().equals(dstInfo.output().element().id())); - - TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); - TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); - - sBuilder.matchInPort(inPort.number()) - .matchEthDst(dstInfo.mac()); - if (isTunnelPort(inPort)) { - sBuilder.matchTunnelId(dstInfo.tunnelId()); - } - - tBuilder.setOutput(dstInfo.output().number()); - - return DefaultForwardingObjective.builder() - .withSelector(sBuilder.build()) - .withTreatment(tBuilder.build()) - .withPriority(DEFAULT_PRIORITY) - .withFlag(ForwardingObjective.Flag.VERSATILE) - .fromApp(appId) - .makePermanent(); - } - - /** - * Returns forwarding objective builder to provision basic virtual tenant network. - * This method cares for the traffics whose source and destination is not the same. - * - * @param deviceId device id to install flow rules - * @param inPort in port - * @param dstInfo destination information - * @return forwarding objective, or null if it fails to build it - */ - private ForwardingObjective.Builder vtnRulesRemoteNode(DeviceId deviceId, Port inPort, DestinationInfo dstInfo) { - checkArgument(isTunnelPort(dstInfo.output())); - - TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); - TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); - - ExtensionTreatment extTreatment = - getTunnelDstInstruction(deviceId, dstInfo.remoteIp().getIp4Address()); - if (extTreatment == null) { - return null; - } - - sBuilder.matchInPort(inPort.number()) - .matchEthDst(dstInfo.mac()); - - tBuilder.extension(extTreatment, deviceId) - .setTunnelId(dstInfo.tunnelId()) - .setOutput(dstInfo.output().number()); - - return DefaultForwardingObjective.builder() - .withSelector(sBuilder.build()) - .withTreatment(tBuilder.build()) - .withPriority(DEFAULT_PRIORITY) - .withFlag(ForwardingObjective.Flag.VERSATILE) - .fromApp(appId) - .makePermanent(); - } - - /** - * Checks if a given port is tunnel interface or not. - * It assumes the tunnel interface contains tunnelType string in its name. - * - * @param port port - * @return true if the port is tunnel interface, false otherwise. - */ - private boolean isTunnelPort(Port port) { - return port.annotations().value("portName").contains(tunnelType); - } - - /** - * Returns extension instruction to set tunnel destination. - * - * @param deviceId device id - * @param remoteIp tunnel destination address - * @return extension treatment or null if it fails to get instruction - */ - private ExtensionTreatment getTunnelDstInstruction(DeviceId deviceId, Ip4Address remoteIp) { - try { - Driver driver = driverService.getDriver(deviceId); - DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); - ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class); - - ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type()); - treatment.setPropertyValue("tunnelDst", remoteIp); - - return treatment; - } catch (ItemNotFoundException | UnsupportedOperationException | ExtensionPropertyException e) { - log.error("Failed to get extension instruction to set tunnel dst {}", deviceId); - return null; - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java deleted file mode 100644 index 5ab7bafa..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -import java.util.List; - -/** - * Service for provisioning overlay virtual networks on compute nodes. - */ -public interface CordVtnService { - - String CORDVTN_APP_ID = "org.onosproject.cordvtn"; - /** - * Adds a new node to the service. - * - * @param node cordvtn node - */ - void addNode(CordVtnNode node); - - /** - * Deletes a node from the service. - * - * @param node cordvtn node - */ - void deleteNode(CordVtnNode node); - - /** - * Initiates node to serve virtual tenant network. - * - * @param node cordvtn node - */ - void initNode(CordVtnNode node); - - /** - * Returns the number of the nodes known to the service. - * - * @return number of nodes - */ - int getNodeCount(); - - /** - * Returns node initialization state. - * - * @param node cordvtn node - * @return true if initial node setup is completed, otherwise false - */ - boolean getNodeInitState(CordVtnNode node); - - /** - * Returns all nodes known to the service. - * - * @return list of nodes - */ - List<CordVtnNode> getNodes(); -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DestinationInfo.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DestinationInfo.java deleted file mode 100644 index 290cc170..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DestinationInfo.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.cordvtn; - -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onosproject.net.Port; - -import java.util.List; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Contains destination information. - */ -public final class DestinationInfo { - - private final Port output; - private final List<IpAddress> ip; - private final MacAddress mac; - private final IpAddress remoteIp; - private final long tunnelId; - - /** - * Creates a new destination information. - * - * @param output output port - * @param ip destination ip address - * @param mac destination mac address - * @param remoteIp tunnel remote ip address - * @param tunnelId segment id - */ - public DestinationInfo(Port output, List<IpAddress> ip, MacAddress mac, - IpAddress remoteIp, long tunnelId) { - this.output = checkNotNull(output); - this.ip = ip; - this.mac = mac; - this.remoteIp = remoteIp; - this.tunnelId = tunnelId; - } - - /** - * Returns output port. - * - * @return port - */ - public Port output() { - return output; - } - - /** - * Returns destination ip addresses. - * - * @return list of ip address - */ - public List<IpAddress> ip() { - return ip; - } - - /** - * Returns destination mac address. - * - * @return mac address - */ - public MacAddress mac() { - return mac; - } - - /** - * Returns tunnel remote ip address. - * - * @return ip address - */ - public IpAddress remoteIp() { - return remoteIp; - } - - /** - * Returns tunnel id. - * - * @return tunnel id - */ - public long tunnelId() { - return tunnelId; - } - - /** - * Returns a new destination info builder. - * - * @return destination info builder - */ - public static DestinationInfo.Builder builder(Port output) { - return new Builder(output); - } - - /** - * DestinationInfo builder class. - */ - public static final class Builder { - - private final Port output; - private List<IpAddress> ip; - private MacAddress mac; - private IpAddress remoteIp; - private long tunnelId; - - /** - * Creates a new destination information builder. - * - * @param output output port - */ - public Builder(Port output) { - this.output = checkNotNull(output, "Output port cannot be null"); - } - - /** - * Sets the destination ip address. - * - * @param ip ip address - * @return destination info builder - */ - public Builder setIp(List<IpAddress> ip) { - this.ip = checkNotNull(ip, "IP cannot be null"); - return this; - } - - /** - * Sets the destination mac address. - * - * @param mac mac address - * @return destination info builder - */ - public Builder setMac(MacAddress mac) { - this.mac = checkNotNull(mac, "MAC address cannot be null"); - return this; - } - - /** - * Sets the tunnel remote ip address. - * - * @param remoteIp ip address - * @return destination info builder - */ - public Builder setRemoteIp(IpAddress remoteIp) { - this.remoteIp = checkNotNull(remoteIp, "Remote IP address cannot be null"); - return this; - } - - /** - * Sets the tunnel id. - * - * @param tunnelId tunnel id - * @return destination info builder - */ - public Builder setTunnelId(long tunnelId) { - this.tunnelId = checkNotNull(tunnelId, "Tunnel ID cannot be null"); - return this; - } - - /** - * Build a destination information. - * - * @return destination info object - */ - public DestinationInfo build() { - return new DestinationInfo(this); - } - } - - private DestinationInfo(Builder builder) { - output = builder.output; - ip = builder.ip; - mac = builder.mac; - remoteIp = builder.remoteIp; - tunnelId = builder.tunnelId; - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeAddCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeAddCommand.java deleted file mode 100644 index 1b7d9866..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeAddCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.CordVtnNode; -import org.onosproject.net.DeviceId; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Adds a new node to the service. - */ -@Command(scope = "onos", name = "cordvtn-node-add", - description = "Adds a new node to CORD VTN service") -public class CordVtnNodeAddCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "hostname", description = "Hostname", - required = true, multiValued = false) - private String hostname = null; - - @Argument(index = 1, name = "ovsdb", - description = "OVSDB server listening address (ip:port)", - required = true, multiValued = false) - private String ovsdb = null; - - @Argument(index = 2, name = "bridgeId", - description = "Device ID of integration bridge", - required = true, multiValued = false) - private String bridgeId = null; - - @Override - protected void execute() { - checkArgument(ovsdb.contains(":"), "OVSDB address should be ip:port format"); - checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format"); - - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - String[] ipPort = ovsdb.split(":"); - CordVtnNode node = new CordVtnNode(hostname, - IpAddress.valueOf(ipPort[0]), - TpPort.tpPort(Integer.parseInt(ipPort[1])), - DeviceId.deviceId(bridgeId)); - service.addNode(node); - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeDeleteCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeDeleteCommand.java deleted file mode 100644 index 0446fc6a..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeDeleteCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.CordVtnNode; - -import java.util.NoSuchElementException; - -/** - * Deletes nodes from the service. - */ -@Command(scope = "onos", name = "cordvtn-node-delete", - description = "Deletes nodes from CORD VTN service") -public class CordVtnNodeDeleteCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "hostnames", description = "Hostname(s)", - required = true, multiValued = true) - private String[] hostnames = null; - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - - for (String hostname : hostnames) { - CordVtnNode node; - try { - node = service.getNodes() - .stream() - .filter(n -> n.hostname().equals(hostname)) - .findFirst().get(); - } catch (NoSuchElementException e) { - print("Unable to find %s", hostname); - continue; - } - - service.deleteNode(node); - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeInitCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeInitCommand.java deleted file mode 100644 index dd77a9c3..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeInitCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.CordVtnNode; - -import java.util.NoSuchElementException; - -/** - * Initializes nodes for CordVtn service. - */ -@Command(scope = "onos", name = "cordvtn-node-init", - description = "Initializes nodes for CORD VTN service") -public class CordVtnNodeInitCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "hostnames", description = "Hostname(s)", - required = true, multiValued = true) - private String[] hostnames = null; - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - - for (String hostname : hostnames) { - CordVtnNode node; - try { - node = service.getNodes() - .stream() - .filter(n -> n.hostname().equals(hostname)) - .findFirst().get(); - } catch (NoSuchElementException e) { - print("Unable to find %s", hostname); - continue; - } - - service.initNode(node); - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeListCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeListCommand.java deleted file mode 100644 index 83e58598..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/CordVtnNodeListCommand.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.cordvtn.cli; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.CordVtnNode; - -import java.util.Collections; -import java.util.List; - -/** - * Lists all nodes registered to the service. - */ -@Command(scope = "onos", name = "cordvtn-nodes", - description = "Lists all nodes registered in CORD VTN service") -public class CordVtnNodeListCommand extends AbstractShellCommand { - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - List<CordVtnNode> nodes = service.getNodes(); - Collections.sort(nodes, CordVtnNode.CORDVTN_NODE_COMPARATOR); - - if (outputJson()) { - print("%s", json(service, nodes)); - } else { - for (CordVtnNode node : nodes) { - print("hostname=%s, ovsdb=%s, br-int=%s, init=%s", - node.hostname(), - node.ovsdbIp().toString() + ":" + node.ovsdbPort().toString(), - node.intBrId().toString(), - getState(service, node)); - } - print("Total %s nodes", service.getNodeCount()); - } - } - - private JsonNode json(CordVtnService service, List<CordVtnNode> nodes) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - for (CordVtnNode node : nodes) { - String ipPort = node.ovsdbIp().toString() + ":" + node.ovsdbPort().toString(); - result.add(mapper.createObjectNode() - .put("hostname", node.hostname()) - .put("ovsdb", ipPort) - .put("brInt", node.intBrId().toString()) - .put("init", getState(service, node))); - } - return result; - } - - private String getState(CordVtnService service, CordVtnNode node) { - return service.getNodeInitState(node) ? "COMPLETE" : "INCOMPLETE"; - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/package-info.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/package-info.java deleted file mode 100644 index 686172ce..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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. - */ - -/** - * Console commands to manage OVSDB nodes for cordvtn. - */ -package org.onosproject.cordvtn.cli;
\ No newline at end of file diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/package-info.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/package-info.java deleted file mode 100644 index 1c13737f..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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. - */ - -/** - * Application for provisioning virtual tenant networks. - */ -package org.onosproject.cordvtn;
\ No newline at end of file |