aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps')
-rw-r--r--framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java563
-rw-r--r--framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java239
-rw-r--r--framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java151
-rw-r--r--framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java259
-rw-r--r--framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java224
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java453
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java75
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java8
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java41
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java99
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java71
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java65
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java60
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.java57
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java60
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.java74
-rw-r--r--framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml11
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java8
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java13
-rw-r--r--framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java36
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java17
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java29
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java29
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java165
-rw-r--r--framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml2
-rw-r--r--framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java6
-rw-r--r--framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java359
-rw-r--r--framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java2
-rw-r--r--framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java34
-rw-r--r--framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java168
-rw-r--r--framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java2
-rw-r--r--framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java18
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java132
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java12
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java127
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java230
-rw-r--r--framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java14
-rw-r--r--framework/src/onos/apps/vtn/pom.xml27
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java52
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java69
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java68
-rw-r--r--framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java672
-rw-r--r--framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java20
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java16
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java148
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java68
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java140
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java65
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java102
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.java64
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java117
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java66
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java82
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java63
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java68
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java68
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java64
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java83
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java65
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java64
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java64
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java64
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java76
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java142
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java72
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java66
-rw-r--r--framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java66
-rw-r--r--framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java123
-rw-r--r--framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java41
-rw-r--r--framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java78
-rw-r--r--framework/src/onos/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java545
74 files changed, 1188 insertions, 6373 deletions
diff --git a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java b/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java
deleted file mode 100644
index 567944a6..00000000
--- a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * Copyright 2015 AT&T Foundry
- *
- * 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.aaa;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.nio.ByteBuffer;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-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.onlab.packet.DeserializationException;
-import org.onlab.packet.EAP;
-import org.onlab.packet.EAPOL;
-import org.onlab.packet.EthType;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.MacAddress;
-import org.onlab.packet.RADIUS;
-import org.onlab.packet.RADIUSAttribute;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
-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.flow.DefaultTrafficSelector;
-import org.onosproject.net.flow.DefaultTrafficTreatment;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.packet.DefaultOutboundPacket;
-import org.onosproject.net.packet.InboundPacket;
-import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.packet.PacketContext;
-import org.onosproject.net.packet.PacketProcessor;
-import org.onosproject.net.packet.PacketService;
-import org.onosproject.xosintegration.VoltTenantService;
-import org.slf4j.Logger;
-
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
-import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
-import static org.onosproject.net.packet.PacketPriority.CONTROL;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * AAA application for ONOS.
- */
-@Component(immediate = true)
-public class AAA {
-
- // for verbose output
- private final Logger log = getLogger(getClass());
-
- // a list of our dependencies :
- // to register with ONOS as an application - described next
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- // to receive Packet-in events that we'll respond to
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected PacketService packetService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected VoltTenantService voltTenantService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected NetworkConfigRegistry netCfgService;
-
- // Parsed RADIUS server addresses
- protected InetAddress radiusIpAddress;
- protected String radiusMacAddress;
-
- // NAS IP address
- protected InetAddress nasIpAddress;
- protected String nasMacAddress;
-
- // RADIUS server secret
- protected String radiusSecret;
-
- // ID of RADIUS switch
- protected String radiusSwitch;
-
- // RADIUS port number
- protected long radiusPort;
-
- // RADIUS server TCP port number
- protected short radiusServerPort;
-
- // our application-specific event handler
- private ReactivePacketProcessor processor = new ReactivePacketProcessor();
-
- // our unique identifier
- private ApplicationId appId;
-
- // Socket used for UDP communications with RADIUS server
- private DatagramSocket radiusSocket;
-
- // Executor for RADIUS communication thread
- private ExecutorService executor;
-
- // Configuration properties factory
- private final ConfigFactory factory =
- new ConfigFactory<ApplicationId, AAAConfig>(APP_SUBJECT_FACTORY,
- AAAConfig.class,
- "AAA") {
- @Override
- public AAAConfig createConfig() {
- return new AAAConfig();
- }
- };
-
- // Listener for config changes
- private final InternalConfigListener cfgListener = new InternalConfigListener();
-
- /**
- * Builds an EAPOL packet based on the given parameters.
- *
- * @param dstMac destination MAC address
- * @param srcMac source MAC address
- * @param vlan vlan identifier
- * @param eapolType EAPOL type
- * @param eap EAP payload
- * @return Ethernet frame
- */
- private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac,
- short vlan, byte eapolType, EAP eap) {
-
- Ethernet eth = new Ethernet();
- eth.setDestinationMACAddress(dstMac.toBytes());
- eth.setSourceMACAddress(srcMac.toBytes());
- eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
- if (vlan != Ethernet.VLAN_UNTAGGED) {
- eth.setVlanID(vlan);
- }
- //eapol header
- EAPOL eapol = new EAPOL();
- eapol.setEapolType(eapolType);
- eapol.setPacketLength(eap.getLength());
-
- //eap part
- eapol.setPayload(eap);
-
- eth.setPayload(eapol);
- eth.setPad(true);
- return eth;
- }
-
- @Activate
- public void activate() {
- netCfgService.addListener(cfgListener);
- netCfgService.registerConfigFactory(factory);
-
- // "org.onosproject.aaa" is the FQDN of our app
- appId = coreService.registerApplication("org.onosproject.aaa");
-
- cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AAAConfig.class));
-
- // register our event handler
- packetService.addProcessor(processor, PacketProcessor.director(2));
- requestIntercepts();
-
- StateMachine.initializeMaps();
-
- try {
- radiusSocket = new DatagramSocket(radiusServerPort);
- } catch (Exception ex) {
- log.error("Can't open RADIUS socket", ex);
- }
-
- executor = Executors.newSingleThreadExecutor(
- new ThreadFactoryBuilder()
- .setNameFormat("AAA-radius-%d").build());
- executor.execute(radiusListener);
- }
-
- @Deactivate
- public void deactivate() {
- appId = coreService.registerApplication("org.onosproject.aaa");
- withdrawIntercepts();
- // de-register and null our handler
- packetService.removeProcessor(processor);
- processor = null;
- StateMachine.destroyMaps();
- radiusSocket.close();
- executor.shutdownNow();
- }
-
- protected void sendRADIUSPacket(RADIUS radiusPacket) {
-
- try {
- final byte[] data = radiusPacket.serialize();
- final DatagramSocket socket = radiusSocket;
-
- DatagramPacket packet =
- new DatagramPacket(data, data.length,
- radiusIpAddress, radiusServerPort);
-
- socket.send(packet);
- } catch (IOException e) {
- log.info("Cannot send packet to RADIUS server", e);
- }
- }
-
- /**
- * Request packet in via PacketService.
- */
- private void requestIntercepts() {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
- packetService.requestPackets(selector.build(),
- CONTROL, appId);
- }
-
- /**
- * Cancel request for packet in via PacketService.
- */
- private void withdrawIntercepts() {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort());
- packetService.cancelPackets(selector.build(), CONTROL, appId);
- }
-
- /**
- * Send the ethernet packet to the supplicant.
- *
- * @param ethernetPkt the ethernet packet
- * @param connectPoint the connect point to send out
- */
- private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) {
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
- OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(),
- treatment, ByteBuffer.wrap(ethernetPkt.serialize()));
- packetService.emit(packet);
- }
-
- // our handler defined as a private inner class
-
- /**
- * Packet processor responsible for forwarding packets along their paths.
- */
- private class ReactivePacketProcessor implements PacketProcessor {
- @Override
- public void process(PacketContext context) {
-
- // Extract the original Ethernet frame from the packet information
- InboundPacket pkt = context.inPacket();
- Ethernet ethPkt = pkt.parsed();
- if (ethPkt == null) {
- return;
- }
- try {
- // identify if incoming packet comes from supplicant (EAP) or RADIUS
- switch (EthType.EtherType.lookup(ethPkt.getEtherType())) {
- case EAPOL:
- handleSupplicantPacket(context.inPacket());
- break;
- default:
- log.trace("Skipping Ethernet packet type {}",
- EthType.EtherType.lookup(ethPkt.getEtherType()));
- }
- } catch (StateMachineException e) {
- log.warn("Unable to process RADIUS packet:", e);
- }
- }
-
- /**
- * Creates and initializes common fields of a RADIUS packet.
- *
- * @param stateMachine state machine for the request
- * @param eapPacket EAP packet
- * @return RADIUS packet
- */
- private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) {
- RADIUS radiusPayload =
- new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST,
- eapPacket.getIdentifier());
-
- // set Request Authenticator in StateMachine
- stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
-
- radiusPayload.setIdentifier(identifier);
- radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME,
- stateMachine.username());
-
- radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP,
- AAA.this.nasIpAddress.getAddress());
-
- radiusPayload.encapsulateMessage(eapPacket);
-
- return radiusPayload;
- }
-
- /**
- * Handles PAE packets (supplicant).
- *
- * @param inPacket Ethernet packet coming from the supplicant
- */
- private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException {
- Ethernet ethPkt = inPacket.parsed();
- // Where does it come from?
- MacAddress srcMAC = ethPkt.getSourceMAC();
-
- DeviceId deviceId = inPacket.receivedFrom().deviceId();
- PortNumber portNumber = inPacket.receivedFrom().port();
- String sessionId = deviceId.toString() + portNumber.toString();
- StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId);
- if (stateMachine == null) {
- stateMachine = new StateMachine(sessionId, voltTenantService);
- }
-
-
- EAPOL eapol = (EAPOL) ethPkt.getPayload();
-
- switch (eapol.getEapolType()) {
- case EAPOL.EAPOL_START:
- stateMachine.start();
- stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom());
-
- //send an EAP Request/Identify to the supplicant
- EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null);
- Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(nasMacAddress),
- ethPkt.getVlanID(), EAPOL.EAPOL_PACKET,
- eapPayload);
- stateMachine.setSupplicantAddress(srcMAC);
- stateMachine.setVlanId(ethPkt.getVlanID());
-
- sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
-
- break;
- case EAPOL.EAPOL_PACKET:
- RADIUS radiusPayload;
- // check if this is a Response/Identify or a Response/TLS
- EAP eapPacket = (EAP) eapol.getPayload();
-
- byte dataType = eapPacket.getDataType();
- switch (dataType) {
-
- case EAP.ATTR_IDENTITY:
- // request id access to RADIUS
- stateMachine.setUsername(eapPacket.getData());
-
- radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket);
- radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
-
- sendRADIUSPacket(radiusPayload);
-
- // change the state to "PENDING"
- stateMachine.requestAccess();
- break;
- case EAP.ATTR_MD5:
- // verify if the EAP identifier corresponds to the
- // challenge identifier from the client state
- // machine.
- if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) {
- //send the RADIUS challenge response
- radiusPayload =
- getRadiusPayload(stateMachine,
- stateMachine.identifier(),
- eapPacket);
-
- radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
- stateMachine.challengeState());
- radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
- sendRADIUSPacket(radiusPayload);
- }
- break;
- case EAP.ATTR_TLS:
- // request id access to RADIUS
- radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket);
-
- radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
- stateMachine.challengeState());
- stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode());
-
- radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret);
- sendRADIUSPacket(radiusPayload);
-
- if (stateMachine.state() != StateMachine.STATE_PENDING) {
- stateMachine.requestAccess();
- }
-
- break;
- default:
- return;
- }
- break;
- default:
- log.trace("Skipping EAPOL message {}", eapol.getEapolType());
- }
-
- }
- }
-
- class RadiusListener implements Runnable {
-
- /**
- * Handles RADIUS packets.
- *
- * @param radiusPacket RADIUS packet coming from the RADIUS server.
- * @throws StateMachineException if an illegal state transition is triggered
- */
- protected void handleRadiusPacket(RADIUS radiusPacket) throws StateMachineException {
- StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier());
- if (stateMachine == null) {
- log.error("Invalid session identifier, exiting...");
- return;
- }
-
- EAP eapPayload;
- Ethernet eth;
- switch (radiusPacket.getCode()) {
- case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE:
- byte[] challengeState =
- radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE).getValue();
- eapPayload = radiusPacket.decapsulateMessage();
- stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState);
- eth = buildEapolResponse(stateMachine.supplicantAddress(),
- MacAddress.valueOf(nasMacAddress),
- stateMachine.vlanId(),
- EAPOL.EAPOL_PACKET,
- eapPayload);
- sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
- break;
- case RADIUS.RADIUS_CODE_ACCESS_ACCEPT:
- //send an EAPOL - Success to the supplicant.
- byte[] eapMessage =
- radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue();
- eapPayload = new EAP();
- eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length);
- eth = buildEapolResponse(stateMachine.supplicantAddress(),
- MacAddress.valueOf(nasMacAddress),
- stateMachine.vlanId(),
- EAPOL.EAPOL_PACKET,
- eapPayload);
- sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint());
-
- stateMachine.authorizeAccess();
- break;
- case RADIUS.RADIUS_CODE_ACCESS_REJECT:
- stateMachine.denyAccess();
- break;
- default:
- log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode());
- }
- }
-
-
- @Override
- public void run() {
- boolean done = false;
- int packetNumber = 1;
-
- log.info("UDP listener thread starting up");
- RADIUS inboundRadiusPacket;
- while (!done) {
- try {
- byte[] packetBuffer = new byte[RADIUS.RADIUS_MAX_LENGTH];
- DatagramPacket inboundBasePacket =
- new DatagramPacket(packetBuffer, packetBuffer.length);
- DatagramSocket socket = radiusSocket;
- socket.receive(inboundBasePacket);
- log.info("Packet #{} received", packetNumber++);
- try {
- inboundRadiusPacket =
- RADIUS.deserializer()
- .deserialize(inboundBasePacket.getData(),
- 0,
- inboundBasePacket.getLength());
- handleRadiusPacket(inboundRadiusPacket);
- } catch (DeserializationException dex) {
- log.error("Cannot deserialize packet", dex);
- } catch (StateMachineException sme) {
- log.error("Illegal state machine operation", sme);
- }
-
- } catch (IOException e) {
- log.info("Socket was closed, exiting listener thread");
- done = true;
- }
- }
- }
- }
-
- RadiusListener radiusListener = new RadiusListener();
-
- private class InternalConfigListener implements NetworkConfigListener {
-
- /**
- * Reconfigures the DHCP Server according to the configuration parameters passed.
- *
- * @param cfg configuration object
- */
- private void reconfigureNetwork(AAAConfig cfg) {
- AAAConfig newCfg;
- if (cfg == null) {
- newCfg = new AAAConfig();
- } else {
- newCfg = cfg;
- }
- if (newCfg.nasIp() != null) {
- nasIpAddress = newCfg.nasIp();
- }
- if (newCfg.radiusIp() != null) {
- radiusIpAddress = newCfg.radiusIp();
- }
- if (newCfg.radiusMac() != null) {
- radiusMacAddress = newCfg.radiusMac();
- }
- if (newCfg.nasMac() != null) {
- nasMacAddress = newCfg.nasMac();
- }
- if (newCfg.radiusSecret() != null) {
- radiusSecret = newCfg.radiusSecret();
- }
- if (newCfg.radiusSwitch() != null) {
- radiusSwitch = newCfg.radiusSwitch();
- }
- if (newCfg.radiusPort() != -1) {
- radiusPort = newCfg.radiusPort();
- }
- if (newCfg.radiusServerUDPPort() != -1) {
- radiusServerPort = newCfg.radiusServerUDPPort();
- }
- }
-
- @Override
- public void event(NetworkConfigEvent event) {
-
- if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
- event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
- event.configClass().equals(AAAConfig.class)) {
-
- AAAConfig cfg = netCfgService.getConfig(appId, AAAConfig.class);
- reconfigureNetwork(cfg);
- log.info("Reconfigured");
- }
- }
- }
-
-
-}
diff --git a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java b/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java
deleted file mode 100644
index 73be7691..00000000
--- a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java
+++ /dev/null
@@ -1,239 +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.aaa;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.config.Config;
-import org.onosproject.net.config.basics.BasicElementConfig;
-
-/**
- * Network config for the AAA app.
- */
-public class AAAConfig extends Config<ApplicationId> {
-
- private static final String RADIUS_IP = "radiusIp";
- private static final String RADIUS_SERVER_PORT = "1812";
- private static final String RADIUS_MAC = "radiusMac";
- private static final String NAS_IP = "nasIp";
- private static final String NAS_MAC = "nasMac";
- private static final String RADIUS_SECRET = "radiusSecret";
- private static final String RADIUS_SWITCH = "radiusSwitch";
- private static final String RADIUS_PORT = "radiusPort";
-
- // RADIUS server IP address
- protected static final String DEFAULT_RADIUS_IP = "10.128.10.4";
-
- // RADIUS MAC address
- protected static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10";
-
- // NAS IP address
- protected static final String DEFAULT_NAS_IP = "10.128.9.244";
-
- // NAS MAC address
- protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01";
-
- // RADIUS server shared secret
- protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret";
-
- // Radius Switch Id
- protected static final String DEFAULT_RADIUS_SWITCH = "of:90e2ba82f97791e9";
-
- // Radius Port Number
- protected static final String DEFAULT_RADIUS_PORT = "129";
-
- // Radius Server UDP Port Number
- protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812";
-
- /**
- * Gets the value of a string property, protecting for an empty
- * JSON object.
- *
- * @param name name of the property
- * @param defaultValue default value if none has been specified
- * @return String value if one os found, default value otherwise
- */
- private String getStringProperty(String name, String defaultValue) {
- if (object == null) {
- return defaultValue;
- }
- return get(name, defaultValue);
- }
-
- /**
- * Returns the NAS ip.
- *
- * @return ip address or null if not set
- */
- public InetAddress nasIp() {
- try {
- return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP));
- } catch (UnknownHostException e) {
- return null;
- }
- }
-
- /**
- * Sets the NAS ip.
- *
- * @param ip new ip address; null to clear
- * @return self
- */
- public BasicElementConfig nasIp(String ip) {
- return (BasicElementConfig) setOrClear(NAS_IP, ip);
- }
-
- /**
- * Returns the RADIUS server ip.
- *
- * @return ip address or null if not set
- */
- public InetAddress radiusIp() {
- try {
- return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP));
- } catch (UnknownHostException e) {
- return null;
- }
- }
-
- /**
- * Sets the RADIUS server ip.
- *
- * @param ip new ip address; null to clear
- * @return self
- */
- public BasicElementConfig radiusIp(String ip) {
- return (BasicElementConfig) setOrClear(RADIUS_IP, ip);
- }
-
- /**
- * Returns the RADIUS MAC address.
- *
- * @return mac address or null if not set
- */
- public String radiusMac() {
- return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC);
- }
-
- /**
- * Sets the RADIUS MAC address.
- *
- * @param mac new MAC address; null to clear
- * @return self
- */
- public BasicElementConfig radiusMac(String mac) {
- return (BasicElementConfig) setOrClear(RADIUS_MAC, mac);
- }
-
- /**
- * Returns the RADIUS MAC address.
- *
- * @return mac address or null if not set
- */
- public String nasMac() {
- return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC);
- }
-
- /**
- * Sets the RADIUS MAC address.
- *
- * @param mac new MAC address; null to clear
- * @return self
- */
- public BasicElementConfig nasMac(String mac) {
- return (BasicElementConfig) setOrClear(NAS_MAC, mac);
- }
-
- /**
- * Returns the RADIUS secret.
- *
- * @return radius secret or null if not set
- */
- public String radiusSecret() {
- return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET);
- }
-
- /**
- * Sets the RADIUS secret.
- *
- * @param secret new MAC address; null to clear
- * @return self
- */
- public BasicElementConfig radiusSecret(String secret) {
- return (BasicElementConfig) setOrClear(RADIUS_SECRET, secret);
- }
-
- /**
- * Returns the ID of the RADIUS switch.
- *
- * @return radius switch ID or null if not set
- */
- public String radiusSwitch() {
- return getStringProperty(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH);
- }
-
- /**
- * Sets the ID of the RADIUS switch.
- *
- * @param switchId new RADIUS switch ID; null to clear
- * @return self
- */
- public BasicElementConfig radiusSwitch(String switchId) {
- return (BasicElementConfig) setOrClear(RADIUS_SWITCH, switchId);
- }
-
- /**
- * Returns the RADIUS port.
- *
- * @return radius port or null if not set
- */
- public long radiusPort() {
- return Integer.parseInt(getStringProperty(RADIUS_PORT, DEFAULT_RADIUS_PORT));
- }
-
- /**
- * Sets the RADIUS port.
- *
- * @param port new RADIUS port; null to clear
- * @return self
- */
- public BasicElementConfig radiusPort(long port) {
- return (BasicElementConfig) setOrClear(RADIUS_PORT, port);
- }
-
- /**
- * Returns the RADIUS server UDP port.
- *
- * @return radius server UDP port.
- */
- public short radiusServerUDPPort() {
- return Short.parseShort(getStringProperty(RADIUS_SERVER_PORT,
- DEFAULT_RADIUS_SERVER_PORT));
- }
-
- /**
- * Sets the RADIUS port.
- *
- * @param port new RADIUS UDP port; -1 to clear
- * @return self
- */
- public BasicElementConfig radiusServerUDPPort(short port) {
- return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port);
- }
-
-}
diff --git a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java b/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java
deleted file mode 100644
index fb513ced..00000000
--- a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2014 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.aaa;
-
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.onlab.packet.EAP;
-import org.onlab.packet.EAPOL;
-import org.onlab.packet.Ethernet;
-import org.onosproject.core.CoreServiceAdapter;
-import org.onosproject.net.config.Config;
-import org.onosproject.net.config.NetworkConfigRegistryAdapter;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertThat;
-
-/**
- * Set of tests of the ONOS application component. These use an existing RADIUS
- * server and sends live packets over the network to it.
- */
-@Ignore ("This should not be run as part of the standard build")
-public class AAAIntegrationTest extends AAATestBase {
-
- private AAA aaa;
-
- /**
- * Mocks the network config registry.
- */
- @SuppressWarnings("unchecked")
- static final class TestNetworkConfigRegistry
- extends NetworkConfigRegistryAdapter {
- @Override
- public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
- return (C) new AAAConfig();
- }
- }
-
- /**
- * Sets up the services required by the AAA application.
- */
- @Before
- public void setUp() {
- aaa = new AAA();
- aaa.netCfgService = new TestNetworkConfigRegistry();
- aaa.coreService = new CoreServiceAdapter();
- aaa.packetService = new MockPacketService();
- aaa.activate();
- }
-
- /**
- * Fetches the sent packet at the given index. The requested packet
- * must be the last packet on the list.
- *
- * @param index index into sent packets array
- * @return packet
- */
- private Ethernet fetchPacket(int index) {
- for (int iteration = 0; iteration < 20; iteration++) {
- if (savedPackets.size() > index) {
- return (Ethernet) savedPackets.get(index);
- } else {
- try {
- Thread.sleep(250);
- } catch (Exception ex) {
- return null;
- }
- }
- }
- return null;
- }
-
- /**
- * Tests the authentication path through the AAA application by sending
- * packets to the RADIUS server and checking the state machine
- * transitions.
- *
- * @throws Exception when an unhandled error occurs
- */
- @Test
- public void testAuthentication() throws Exception {
-
- // (1) Supplicant start up
-
- Ethernet startPacket = constructSupplicantStartPacket();
- sendPacket(startPacket);
-
- Ethernet responsePacket = fetchPacket(0);
- assertThat(responsePacket, notNullValue());
- checkRadiusPacket(aaa, responsePacket, EAP.REQUEST);
-
- // (2) Supplicant identify
-
- Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
- sendPacket(identifyPacket);
-
- // State machine should have been created by now
-
- StateMachine stateMachine =
- StateMachine.lookupStateMachineBySessionId(SESSION_ID);
- assertThat(stateMachine, notNullValue());
- assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
-
- // (3) RADIUS MD5 challenge
-
- Ethernet radiusChallengeMD5Packet = fetchPacket(1);
- assertThat(radiusChallengeMD5Packet, notNullValue());
- checkRadiusPacket(aaa, radiusChallengeMD5Packet, EAP.REQUEST);
-
-
- // (4) Supplicant MD5 response
-
- Ethernet md5RadiusPacket =
- constructSupplicantIdentifyPacket(stateMachine,
- EAP.ATTR_MD5,
- stateMachine.challengeIdentifier(),
- radiusChallengeMD5Packet);
- sendPacket(md5RadiusPacket);
-
-
- // (5) RADIUS Success
-
- Ethernet successRadiusPacket = fetchPacket(2);
- assertThat(successRadiusPacket, notNullValue());
- EAPOL successEAPOL = (EAPOL) successRadiusPacket.getPayload();
- EAP successEAP = (EAP) successEAPOL.getPayload();
- assertThat(successEAP.getCode(), is(EAP.SUCCESS));
-
- // State machine should be in authorized state
-
- assertThat(stateMachine, notNullValue());
- assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED));
-
- }
-
-}
-
diff --git a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java b/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java
deleted file mode 100644
index 860a7dbd..00000000
--- a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright 2014 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.aaa;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.packet.BasePacket;
-import org.onlab.packet.DeserializationException;
-import org.onlab.packet.EAP;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.RADIUS;
-import org.onlab.packet.RADIUSAttribute;
-import org.onosproject.core.CoreServiceAdapter;
-import org.onosproject.net.config.Config;
-import org.onosproject.net.config.NetworkConfigRegistryAdapter;
-
-import com.google.common.base.Charsets;
-
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertThat;
-
-/**
- * Set of tests of the ONOS application component.
- */
-public class AAATest extends AAATestBase {
-
- static final String BAD_IP_ADDRESS = "198.51.100.0";
-
- private AAA aaa;
-
- class AAAWithoutRadiusServer extends AAA {
- protected void sendRADIUSPacket(RADIUS radiusPacket) {
- savePacket(radiusPacket);
- }
- }
-
- /**
- * Mocks the AAAConfig class to force usage of an unroutable address for the
- * RADIUS server.
- */
- static class MockAAAConfig extends AAAConfig {
- @Override
- public InetAddress radiusIp() {
- try {
- return InetAddress.getByName(BAD_IP_ADDRESS);
- } catch (UnknownHostException ex) {
- // can't happen
- throw new IllegalStateException(ex);
- }
- }
- }
-
- /**
- * Mocks the network config registry.
- */
- @SuppressWarnings("unchecked")
- private static final class TestNetworkConfigRegistry
- extends NetworkConfigRegistryAdapter {
- @Override
- public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
- AAAConfig aaaConfig = new MockAAAConfig();
- return (C) aaaConfig;
- }
- }
-
- /**
- * Constructs an Ethernet packet containing a RADIUS challenge
- * packet.
- *
- * @param challengeCode code to use in challenge packet
- * @param challengeType type to use in challenge packet
- * @return Ethernet packet
- */
- private RADIUS constructRADIUSCodeAccessChallengePacket(byte challengeCode, byte challengeType) {
-
- String challenge = "12345678901234567";
-
- EAP eap = new EAP(challengeType, (byte) 1, challengeType,
- challenge.getBytes(Charsets.US_ASCII));
- eap.setIdentifier((byte) 1);
-
- RADIUS radius = new RADIUS();
- radius.setCode(challengeCode);
-
- radius.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE,
- challenge.getBytes(Charsets.US_ASCII));
-
- radius.setPayload(eap);
- radius.setAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE,
- eap.serialize());
-
- return radius;
- }
-
- /**
- * Sets up the services required by the AAA application.
- */
- @Before
- public void setUp() {
- aaa = new AAAWithoutRadiusServer();
- aaa.netCfgService = new TestNetworkConfigRegistry();
- aaa.coreService = new CoreServiceAdapter();
- aaa.packetService = new MockPacketService();
- aaa.activate();
- }
-
- /**
- * Tears down the AAA application.
- */
- @After
- public void tearDown() {
- aaa.deactivate();
- }
-
- /**
- * Extracts the RADIUS packet from a packet sent by the supplicant.
- *
- * @param radius RADIUS packet sent by the supplicant
- * @throws DeserializationException if deserialization of the packet contents
- * fails.
- */
- private void checkRADIUSPacketFromSupplicant(RADIUS radius)
- throws DeserializationException {
- assertThat(radius, notNullValue());
-
- EAP eap = radius.decapsulateMessage();
- assertThat(eap, notNullValue());
- }
-
- /**
- * Fetches the sent packet at the given index. The requested packet
- * must be the last packet on the list.
- *
- * @param index index into sent packets array
- * @return packet
- */
- private BasePacket fetchPacket(int index) {
- BasePacket packet = savedPackets.get(index);
- assertThat(packet, notNullValue());
- return packet;
- }
-
- /**
- * Tests the authentication path through the AAA application.
- *
- * @throws DeserializationException if packed deserialization fails.
- */
- @Test
- public void testAuthentication() throws Exception {
-
- // (1) Supplicant start up
-
- Ethernet startPacket = constructSupplicantStartPacket();
- sendPacket(startPacket);
-
- Ethernet responsePacket = (Ethernet) fetchPacket(0);
- checkRadiusPacket(aaa, responsePacket, EAP.ATTR_IDENTITY);
-
- // (2) Supplicant identify
-
- Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
- sendPacket(identifyPacket);
-
- RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1);
-
- checkRADIUSPacketFromSupplicant(radiusIdentifyPacket);
-
- assertThat(radiusIdentifyPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST));
- assertThat(new String(radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME).getValue()),
- is("testuser"));
-
- IpAddress nasIp =
- IpAddress.valueOf(IpAddress.Version.INET,
- radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP)
- .getValue());
- assertThat(nasIp.toString(), is(aaa.nasIpAddress.getHostAddress()));
-
- // State machine should have been created by now
-
- StateMachine stateMachine =
- StateMachine.lookupStateMachineBySessionId(SESSION_ID);
- assertThat(stateMachine, notNullValue());
- assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
-
- // (3) RADIUS MD5 challenge
-
- RADIUS radiusCodeAccessChallengePacket =
- constructRADIUSCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_CHALLENGE, EAP.ATTR_MD5);
- aaa.radiusListener.handleRadiusPacket(radiusCodeAccessChallengePacket);
-
- Ethernet radiusChallengeMD5Packet = (Ethernet) fetchPacket(2);
- checkRadiusPacket(aaa, radiusChallengeMD5Packet, EAP.ATTR_MD5);
-
- // (4) Supplicant MD5 response
-
- Ethernet md5RadiusPacket =
- constructSupplicantIdentifyPacket(stateMachine,
- EAP.ATTR_MD5,
- stateMachine.challengeIdentifier(),
- radiusChallengeMD5Packet);
- sendPacket(md5RadiusPacket);
-
- RADIUS responseMd5RadiusPacket = (RADIUS) fetchPacket(3);
-
- checkRADIUSPacketFromSupplicant(responseMd5RadiusPacket);
- assertThat(responseMd5RadiusPacket.getIdentifier(), is((byte) 0));
- assertThat(responseMd5RadiusPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST));
-
- // State machine should be in pending state
-
- assertThat(stateMachine, notNullValue());
- assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
-
- // (5) RADIUS Success
-
- RADIUS successPacket =
- constructRADIUSCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_ACCEPT, EAP.SUCCESS);
- aaa.radiusListener.handleRadiusPacket((successPacket));
- Ethernet supplicantSuccessPacket = (Ethernet) fetchPacket(4);
-
- checkRadiusPacket(aaa, supplicantSuccessPacket, EAP.SUCCESS);
-
- // State machine should be in authorized state
-
- assertThat(stateMachine, notNullValue());
- assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED));
-
- }
-
- /**
- * Tests the default configuration.
- */
- @Test
- public void testConfig() {
- assertThat(aaa.nasIpAddress.getHostAddress(), is(AAAConfig.DEFAULT_NAS_IP));
- assertThat(aaa.nasMacAddress, is(AAAConfig.DEFAULT_NAS_MAC));
- assertThat(aaa.radiusIpAddress.getHostAddress(), is(BAD_IP_ADDRESS));
- assertThat(aaa.radiusMacAddress, is(AAAConfig.DEFAULT_RADIUS_MAC));
- }
-}
diff --git a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java b/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java
deleted file mode 100644
index dffcba2f..00000000
--- a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java
+++ /dev/null
@@ -1,224 +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.aaa;
-
-import java.nio.ByteBuffer;
-import java.security.MessageDigest;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.onlab.packet.BasePacket;
-import org.onlab.packet.EAP;
-import org.onlab.packet.EAPOL;
-import org.onlab.packet.EthType;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.MacAddress;
-import org.onosproject.net.packet.DefaultInboundPacket;
-import org.onosproject.net.packet.DefaultPacketContext;
-import org.onosproject.net.packet.InboundPacket;
-import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.packet.PacketContext;
-import org.onosproject.net.packet.PacketProcessor;
-import org.onosproject.net.packet.PacketServiceAdapter;
-
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.onosproject.net.NetTestTools.connectPoint;
-
-/**
- * Common methods for AAA app testing.
- */
-public class AAATestBase {
-
- MacAddress clientMac = MacAddress.valueOf("1a:1a:1a:1a:1a:1a");
- MacAddress serverMac = MacAddress.valueOf("2a:2a:2a:2a:2a:2a");
-
- // Our session id will be the device ID ("of:1") with the port ("1") concatenated
- static final String SESSION_ID = "of:11";
-
- List<BasePacket> savedPackets = new LinkedList<>();
- PacketProcessor packetProcessor;
-
- /**
- * Saves the given packet onto the saved packets list.
- *
- * @param packet packet to save
- */
- void savePacket(BasePacket packet) {
- savedPackets.add(packet);
- }
-
- /**
- * Keeps a reference to the PacketProcessor and saves the OutboundPackets.
- */
- class MockPacketService extends PacketServiceAdapter {
-
- @Override
- public void addProcessor(PacketProcessor processor, int priority) {
- packetProcessor = processor;
- }
-
- @Override
- public void emit(OutboundPacket packet) {
- try {
- Ethernet eth = Ethernet.deserializer().deserialize(packet.data().array(),
- 0, packet.data().array().length);
- savePacket(eth);
- } catch (Exception e) {
- fail(e.getMessage());
- }
- }
- }
-
- /**
- * Mocks the DefaultPacketContext.
- */
- final class TestPacketContext extends DefaultPacketContext {
-
- private TestPacketContext(long time, InboundPacket inPkt,
- OutboundPacket outPkt, boolean block) {
- super(time, inPkt, outPkt, block);
- }
-
- @Override
- public void send() {
- // We don't send anything out.
- }
- }
-
- /**
- * Sends an Ethernet packet to the process method of the Packet Processor.
- *
- * @param reply Ethernet packet
- */
- void sendPacket(Ethernet reply) {
- final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize());
- InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1),
- reply,
- byteBuffer);
-
- PacketContext context = new TestPacketContext(127L, inPacket, null, false);
- packetProcessor.process(context);
- }
-
- /**
- * Constructs an Ethernet packet containing identification payload.
- *
- * @return Ethernet packet
- */
- Ethernet constructSupplicantIdentifyPacket(StateMachine stateMachine,
- byte type,
- byte id,
- Ethernet radiusChallenge)
- throws Exception {
- Ethernet eth = new Ethernet();
- eth.setDestinationMACAddress(clientMac.toBytes());
- eth.setSourceMACAddress(serverMac.toBytes());
- eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
- eth.setVlanID((short) 2);
-
- String username = "testuser";
- byte[] data = username.getBytes();
-
-
- if (type == EAP.ATTR_MD5) {
- String password = "testpassword";
- EAPOL eapol = (EAPOL) radiusChallenge.getPayload();
- EAP eap = (EAP) eapol.getPayload();
-
- byte[] identifier = new byte[password.length() + eap.getData().length];
-
- identifier[0] = stateMachine.challengeIdentifier();
- System.arraycopy(password.getBytes(), 0, identifier, 1, password.length());
- System.arraycopy(eap.getData(), 1, identifier, 1 + password.length(), 16);
-
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte[] hash = md.digest(identifier);
- data = new byte[17];
- data[0] = (byte) 16;
- System.arraycopy(hash, 0, data, 1, 16);
- }
- EAP eap = new EAP(EAP.RESPONSE, (byte) 1, type,
- data);
- eap.setIdentifier(id);
-
- // eapol header
- EAPOL eapol = new EAPOL();
- eapol.setEapolType(EAPOL.EAPOL_PACKET);
- eapol.setPacketLength(eap.getLength());
-
- // eap part
- eapol.setPayload(eap);
-
- eth.setPayload(eapol);
- eth.setPad(true);
- return eth;
- }
-
- /**
- * Constructs an Ethernet packet containing a EAPOL_START Payload.
- *
- * @return Ethernet packet
- */
- Ethernet constructSupplicantStartPacket() {
- Ethernet eth = new Ethernet();
- eth.setDestinationMACAddress(clientMac.toBytes());
- eth.setSourceMACAddress(serverMac.toBytes());
- eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
- eth.setVlanID((short) 2);
-
- EAP eap = new EAP(EAPOL.EAPOL_START, (byte) 2, EAPOL.EAPOL_START, null);
-
- // eapol header
- EAPOL eapol = new EAPOL();
- eapol.setEapolType(EAPOL.EAPOL_START);
- eapol.setPacketLength(eap.getLength());
-
- // eap part
- eapol.setPayload(eap);
-
- eth.setPayload(eapol);
- eth.setPad(true);
- return eth;
- }
-
- /**
- * Checks the contents of a RADIUS packet being sent to the RADIUS server.
- *
- * @param radiusPacket packet to check
- * @param code expected code
- */
- void checkRadiusPacket(AAA aaa, Ethernet radiusPacket, byte code) {
-
- assertThat(radiusPacket.getSourceMAC(),
- is(MacAddress.valueOf(aaa.nasMacAddress)));
- assertThat(radiusPacket.getDestinationMAC(), is(serverMac));
-
- assertThat(radiusPacket.getPayload(), instanceOf(EAPOL.class));
- EAPOL eapol = (EAPOL) radiusPacket.getPayload();
- assertThat(eapol, notNullValue());
-
- assertThat(eapol.getEapolType(), is(EAPOL.EAPOL_PACKET));
- assertThat(eapol.getPayload(), instanceOf(EAP.class));
- EAP eap = (EAP) eapol.getPayload();
- assertThat(eap, notNullValue());
-
- assertThat(eap.getCode(), is(code));
- }
-}
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
index e15bc763..c3bf77c5 100644
--- 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
@@ -15,7 +15,6 @@
*/
package org.onosproject.cordvtn;
-import com.google.common.collect.Collections2;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -32,6 +31,7 @@ import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
+import org.onosproject.net.Port;
import org.onosproject.net.behaviour.BridgeConfig;
import org.onosproject.net.behaviour.BridgeName;
import org.onosproject.net.behaviour.ControllerInfo;
@@ -39,6 +39,7 @@ 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;
@@ -54,7 +55,6 @@ 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.onosproject.store.service.Versioned;
import org.slf4j.Logger;
import java.util.ArrayList;
@@ -84,7 +84,8 @@ public class CordVtn implements CordVtnService {
private static final int NUM_THREADS = 1;
private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder()
.register(KryoNamespaces.API)
- .register(DefaultOvsdbNode.class);
+ .register(CordVtnNode.class)
+ .register(NodeState.class);
private static final String DEFAULT_BRIDGE_NAME = "br-int";
private static final String DEFAULT_TUNNEL = "vxlan";
private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() {
@@ -112,6 +113,9 @@ public class CordVtn implements CordVtnService {
protected DriverService driverService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceAdminService adminService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected OvsdbController controller;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -127,12 +131,55 @@ public class CordVtn implements CordVtnService {
private final BridgeHandler bridgeHandler = new BridgeHandler();
private final VmHandler vmHandler = new VmHandler();
- private ConsistentMap<DeviceId, OvsdbNode> nodeStore;
+ private ConsistentMap<CordVtnNode, NodeState> nodeStore;
+
+ 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.<DeviceId, OvsdbNode>consistentMapBuilder()
+ nodeStore = storageService.<CordVtnNode, NodeState>consistentMapBuilder()
.withSerializer(Serializer.using(NODE_SERIALIZER.build()))
.withName("cordvtn-nodestore")
.withApplicationId(appId)
@@ -156,145 +203,272 @@ public class CordVtn implements CordVtnService {
}
@Override
- public void addNode(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
+ public void addNode(CordVtnNode node) {
+ checkNotNull(node);
+
+ nodeStore.putIfAbsent(node, checkNodeState(node));
+ initNode(node);
+ }
- nodeStore.putIfAbsent(ovsdb.deviceId(), ovsdb);
+ @Override
+ public void deleteNode(CordVtnNode node) {
+ checkNotNull(node);
- if (isNodeConnected(ovsdb)) {
- init(ovsdb);
- } else {
- connect(ovsdb);
+ if (getOvsdbConnectionState(node)) {
+ disconnect(node);
}
+
+ nodeStore.remove(node);
}
@Override
- public void deleteNode(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
+ public int getNodeCount() {
+ return nodeStore.size();
+ }
- if (deviceService.getDevice(ovsdb.deviceId()) != null) {
- if (deviceService.isAvailable(ovsdb.deviceId())) {
- log.warn("Cannot delete connected node {}", ovsdb.host());
- return;
- }
- }
- nodeStore.remove(ovsdb.deviceId());
+ @Override
+ public List<CordVtnNode> getNodes() {
+ List<CordVtnNode> nodes = new ArrayList<>();
+ nodes.addAll(nodeStore.keySet());
+ return nodes;
}
@Override
- public void connect(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
+ public void initNode(CordVtnNode node) {
+ checkNotNull(node);
- if (!nodeStore.containsKey(ovsdb.deviceId())) {
- log.warn("Node {} does not exist", ovsdb.host());
+ if (!nodeStore.containsKey(node)) {
+ log.warn("Node {} does not exist, add node first", node.hostname());
return;
}
- if (!isNodeConnected(ovsdb)) {
- controller.connect(ovsdb.ip(), ovsdb.port());
+ NodeState state = getNodeState(node);
+ if (state == null) {
+ return;
+ } else if (state.equals(NodeState.INCOMPLETE)) {
+ state = checkNodeState(node);
}
+
+ state.process(this, node);
}
@Override
- public void disconnect(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
+ public boolean getNodeInitState(CordVtnNode node) {
+ checkNotNull(node);
- if (!nodeStore.containsKey(ovsdb.deviceId())) {
- log.warn("Node {} does not exist", ovsdb.host());
- return;
+ 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;
}
+ }
- if (isNodeConnected(ovsdb)) {
- OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb);
- ovsdbClient.disconnect();
+ /**
+ * 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;
}
}
- private void init(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
+ /**
+ * Performs tasks after node initialization.
+ *
+ * @param node cordvtn node
+ */
+ private void postInit(CordVtnNode node) {
+ disconnect(node);
+ }
+
+ /**
+ * 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(ovsdb.deviceId())) {
- log.warn("Node {} does not exist", ovsdb.host());
+ if (!nodeStore.containsKey(node)) {
+ log.warn("Node {} does not exist", node.hostname());
return;
}
- if (!isNodeConnected(ovsdb)) {
- log.warn("Node {} is not connected", ovsdb.host());
+ 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 (deviceService.getDevice(ovsdb.intBrId()) == null ||
- !deviceService.isAvailable(ovsdb.intBrId())) {
- createIntegrationBridge(ovsdb);
- } else if (!checkVxlanInterface(ovsdb)) {
- createVxlanInterface(ovsdb);
+ if (getOvsdbConnectionState(node)) {
+ OvsdbClientService ovsdbClient = getOvsdbClient(node);
+ ovsdbClient.disconnect();
}
- }
- @Override
- public int getNodeCount() {
- return nodeStore.size();
+ // FIXME remove existing OVSDB device to work around OVSDB device re-connect issue
+ if (deviceService.getDevice(node.ovsdbId()) != null) {
+ adminService.removeDevice(node.ovsdbId());
+ }
}
- @Override
- public OvsdbNode getNode(DeviceId deviceId) {
- Versioned<OvsdbNode> ovsdb = nodeStore.get(deviceId);
- if (ovsdb != null) {
- return ovsdb.value();
- } else {
+ /**
+ * 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;
}
}
- @Override
- public List<OvsdbNode> getNodes() {
- List<OvsdbNode> ovsdbs = new ArrayList<>();
- ovsdbs.addAll(Collections2.transform(nodeStore.values(), Versioned::value));
- return ovsdbs;
- }
-
- @Override
- public boolean isNodeConnected(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
-
- OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb);
- if (ovsdbClient == null) {
- return false;
- } else {
- return ovsdbClient.isConnected();
+ /**
+ * 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;
}
}
- private OvsdbClientService getOvsdbClient(OvsdbNode ovsdb) {
- checkNotNull(ovsdb);
+ /**
+ * 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(ovsdb.ip(), ovsdb.port().toInt()));
+ new OvsdbNodeId(node.ovsdbIp(), node.ovsdbPort().toInt()));
if (ovsdbClient == null) {
- log.debug("Couldn't find ovsdb client for {}", ovsdb.host());
+ log.debug("Couldn't find OVSDB client for {}", node.hostname());
}
return ovsdbClient;
}
- private void createIntegrationBridge(OvsdbNode ovsdb) {
+ /**
+ * 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())
.forEach(controller -> {
ControllerInfo ctrlInfo = new ControllerInfo(controller.ip(), OFPORT, "tcp");
controllers.add(ctrlInfo);
});
- String dpid = ovsdb.intBrId().toString().substring(DPID_BEGIN);
+ String dpid = node.intBrId().toString().substring(DPID_BEGIN);
try {
- DriverHandler handler = driverService.createHandler(ovsdb.deviceId());
+ DriverHandler handler = driverService.createHandler(node.ovsdbId());
BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), dpid, controllers);
} catch (ItemNotFoundException e) {
- log.warn("Failed to create integration bridge on {}", ovsdb.deviceId());
+ log.warn("Failed to create integration bridge on {}", node.ovsdbId());
}
}
- private void createVxlanInterface(OvsdbNode ovsdb) {
+ /**
+ * 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));
@@ -304,38 +478,63 @@ public class CordVtn implements CordVtnService {
TunnelName.tunnelName(DEFAULT_TUNNEL),
optionBuilder.build());
try {
- DriverHandler handler = driverService.createHandler(ovsdb.deviceId());
+ DriverHandler handler = driverService.createHandler(node.ovsdbId());
TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class);
tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), description);
} catch (ItemNotFoundException e) {
- log.warn("Failed to create VXLAN interface on {}", ovsdb.deviceId());
+ log.warn("Failed to create tunnel interface on {}", node.ovsdbId());
}
}
- private boolean checkVxlanInterface(OvsdbNode ovsdb) {
+ /**
+ * 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 {
- DriverHandler handler = driverService.createHandler(ovsdb.deviceId());
- BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
- bridgeConfig.getPorts().stream()
- .filter(p -> p.annotations().value("portName").equals(DEFAULT_TUNNEL))
+ deviceService.getPorts(node.intBrId())
+ .stream()
+ .filter(p -> p.annotations().value("portName").contains(DEFAULT_TUNNEL)
+ && p.isEnabled())
.findAny().get();
- } catch (ItemNotFoundException | NoSuchElementException e) {
+ return true;
+ } catch (NoSuchElementException e) {
return false;
}
- return true;
}
private class InternalDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
+
Device device = event.subject();
- ConnectionHandler handler = (device.type() == SWITCH ? bridgeHandler : ovsdbHandler);
+ ConnectionHandler<Device> handler =
+ (device.type().equals(SWITCH) ? bridgeHandler : ovsdbHandler);
switch (event.type()) {
- case DEVICE_ADDED:
- eventExecutor.submit(() -> handler.connected(device));
+ 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));
@@ -372,17 +571,15 @@ public class CordVtn implements CordVtnService {
@Override
public void connected(Device device) {
- log.info("Ovsdb {} is connected", device.id());
-
- OvsdbNode ovsdb = getNode(device.id());
- if (ovsdb != null) {
- init(ovsdb);
+ CordVtnNode node = getNodeByOvsdbId(device.id());
+ if (node != null) {
+ setNodeState(node, checkNodeState(node));
}
}
@Override
public void disconnected(Device device) {
- log.warn("Ovsdb {} is disconnected", device.id());
+ log.info("OVSDB {} is disconnected", device.id());
}
}
@@ -390,26 +587,56 @@ public class CordVtn implements CordVtnService {
@Override
public void connected(Device device) {
- log.info("Integration Bridge {} is detected", device.id());
-
- OvsdbNode ovsdb;
- try {
- ovsdb = getNodes().stream()
- .filter(node -> node.intBrId().equals(device.id()))
- .findFirst().get();
- } catch (NoSuchElementException e) {
- log.warn("Couldn't find OVSDB associated with {}", device.id());
+ 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;
}
- if (!checkVxlanInterface(ovsdb)) {
- createVxlanInterface(ovsdb);
+ CordVtnNode node = getNodeByBridgeId((DeviceId) port.element().id());
+ if (node != null) {
+ setNodeState(node, checkNodeState(node));
}
}
- @Override
- public void disconnected(Device device) {
- log.info("Integration Bridge {} is vanished", device.id());
+ /**
+ * 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);
+ }
}
}
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
index 550452ce..827ce052 100644
--- 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
@@ -32,77 +32,82 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class CordVtnConfig extends Config<ApplicationId> {
- public static final String OVSDB_NODES = "ovsdbNodes";
- public static final String HOST = "host";
- public static final String IP = "ip";
- public static final String PORT = "port";
+ 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 ovsdb nodes read from network config.
+ * Returns the set of nodes read from network config.
*
- * @return set of OvsdbNodeConfig or null
+ * @return set of CordVtnNodeConfig or null
*/
- public Set<OvsdbNodeConfig> ovsdbNodes() {
- Set<OvsdbNodeConfig> ovsdbNodes = Sets.newHashSet();
+ public Set<CordVtnNodeConfig> cordVtnNodes() {
+ Set<CordVtnNodeConfig> nodes = Sets.newHashSet();
- JsonNode nodes = object.get(OVSDB_NODES);
- if (nodes == null) {
+ JsonNode jsonNodes = object.get(CORDVTN_NODES);
+ if (jsonNodes == null) {
return null;
}
- nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig(
- jsonNode.path(HOST).asText(),
- IpAddress.valueOf(jsonNode.path(IP).asText()),
- TpPort.tpPort(jsonNode.path(PORT).asInt()),
+ 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 ovsdbNodes;
+ return nodes;
}
/**
- * Configuration for an ovsdb node.
+ * Configuration for CordVtn node.
*/
- public static class OvsdbNodeConfig {
+ public static class CordVtnNodeConfig {
- private final String host;
- private final IpAddress ip;
- private final TpPort port;
+ private final String hostname;
+ private final IpAddress ovsdbIp;
+ private final TpPort ovsdbPort;
private final DeviceId bridgeId;
- public OvsdbNodeConfig(String host, IpAddress ip, TpPort port, DeviceId bridgeId) {
- this.host = checkNotNull(host);
- this.ip = checkNotNull(ip);
- this.port = checkNotNull(port);
+ 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 host information of the node.
+ * Returns hostname of the node.
*
- * @return host
+ * @return hostname
*/
- public String host() {
- return this.host;
+ public String hostname() {
+ return this.hostname;
}
/**
- * Returns ip address to access ovsdb-server of the node.
+ * Returns OVSDB ip address of the node.
*
- * @return ip address
+ * @return OVSDB server IP address
*/
- public IpAddress ip() {
- return this.ip;
+ public IpAddress ovsdbIp() {
+ return this.ovsdbIp;
}
/**
- * Returns port number to access ovsdb-server of the node.
+ * Returns OVSDB port number of the node.
*
* @return port number
*/
- public TpPort port() {
- return this.port;
+ 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
index 274ca9b4..f79b4460 100644
--- 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
@@ -88,10 +88,10 @@ public class CordVtnConfigManager {
return;
}
- config.ovsdbNodes().forEach(node -> {
- DefaultOvsdbNode ovsdb = new DefaultOvsdbNode(
- node.host(), node.ip(), node.port(), node.bridgeId());
- cordVtnService.addNode(ovsdb);
+ config.cordVtnNodes().forEach(node -> {
+ CordVtnNode cordVtnNode = new CordVtnNode(
+ node.hostname(), node.ovsdbIp(), node.ovsdbPort(), node.bridgeId());
+ cordVtnService.addNode(cordVtnNode);
});
}
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
index 7e01a452..5ab7bafa 100644
--- 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
@@ -15,8 +15,6 @@
*/
package org.onosproject.cordvtn;
-import org.onosproject.net.DeviceId;
-
import java.util.List;
/**
@@ -28,30 +26,23 @@ public interface CordVtnService {
/**
* Adds a new node to the service.
*
- * @param ovsdb ovsdb node
+ * @param node cordvtn node
*/
- void addNode(OvsdbNode ovsdb);
+ void addNode(CordVtnNode node);
/**
* Deletes a node from the service.
*
- * @param ovsdb ovsdb node
- */
- void deleteNode(OvsdbNode ovsdb);
-
- /**
- * Connect to a node.
- *
- * @param ovsdb ovsdb node
+ * @param node cordvtn node
*/
- void connect(OvsdbNode ovsdb);
+ void deleteNode(CordVtnNode node);
/**
- * Disconnect a node.
+ * Initiates node to serve virtual tenant network.
*
- * @param ovsdb ovsdb node
+ * @param node cordvtn node
*/
- void disconnect(OvsdbNode ovsdb);
+ void initNode(CordVtnNode node);
/**
* Returns the number of the nodes known to the service.
@@ -61,25 +52,17 @@ public interface CordVtnService {
int getNodeCount();
/**
- * Returns OvsdbNode with given device id.
- *
- * @param deviceId device id
- * @return ovsdb node
- */
- OvsdbNode getNode(DeviceId deviceId);
-
- /**
- * Returns connection state of the node.
+ * Returns node initialization state.
*
- * @param ovsdb ovsdb node
- * @return true if the node is connected, false otherwise
+ * @param node cordvtn node
+ * @return true if initial node setup is completed, otherwise false
*/
- boolean isNodeConnected(OvsdbNode ovsdb);
+ boolean getNodeInitState(CordVtnNode node);
/**
* Returns all nodes known to the service.
*
* @return list of nodes
*/
- List<OvsdbNode> getNodes();
+ List<CordVtnNode> getNodes();
}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java
deleted file mode 100644
index 46f6e29c..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java
+++ /dev/null
@@ -1,99 +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.Objects;
-
-/**
- * OvsdbNode implementation.
- */
-public class DefaultOvsdbNode implements OvsdbNode {
-
- private final String host;
- private final IpAddress ip;
- private final TpPort port;
- private final DeviceId brId;
-
- public DefaultOvsdbNode(String host, IpAddress ip, TpPort port, DeviceId brId) {
- this.host = host;
- this.ip = ip;
- this.port = port;
- this.brId = brId;
- }
-
- @Override
- public IpAddress ip() {
- return this.ip;
- }
-
- @Override
- public TpPort port() {
- return this.port;
- }
-
- @Override
- public String host() {
- return this.host;
- }
-
- @Override
- public DeviceId intBrId() {
- return this.brId;
- }
-
- @Override
- public DeviceId deviceId() {
- return DeviceId.deviceId("ovsdb:" + this.ip.toString());
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
-
- if (o instanceof DefaultOvsdbNode) {
- DefaultOvsdbNode that = (DefaultOvsdbNode) o;
- if (this.host.equals(that.host) &&
- this.ip.equals(that.ip) &&
- this.port.equals(that.port) &&
- this.brId.equals(that.brId)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(host, ip, port);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("host", host)
- .add("ip", ip)
- .add("port", port)
- .add("bridgeId", brId)
- .toString();
- }
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java
deleted file mode 100644
index 7a9a06a6..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java
+++ /dev/null
@@ -1,71 +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.TpPort;
-import org.onosproject.net.DeviceId;
-
-import java.util.Comparator;
-
-/**
- * Representation of a node with ovsdb server.
- */
-public interface OvsdbNode {
-
- Comparator<OvsdbNode> OVSDB_NODE_COMPARATOR = new Comparator<OvsdbNode>() {
- @Override
- public int compare(OvsdbNode ovsdb1, OvsdbNode ovsdb2) {
- return ovsdb1.host().compareTo(ovsdb2.host());
- }
- };
-
- /**
- * Returns the IP address of the ovsdb server.
- *
- * @return ip address
- */
- IpAddress ip();
-
- /**
- * Returns the port number of the ovsdb server.
- *
- * @return port number
- */
- TpPort port();
-
- /**
- * Returns the host information of the ovsdb server.
- * It could be hostname or ip address.
- *
- * @return host
- */
- String host();
-
- /**
- * Returns the device id of the ovsdb server.
- *
- * @return device id
- */
- DeviceId deviceId();
-
- /**
- * Returns the device id of the integration bridge associated with the node.
- *
- * @return device id
- */
- DeviceId intBrId();
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java
deleted file mode 100644
index 88d16341..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java
+++ /dev/null
@@ -1,65 +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.DefaultOvsdbNode;
-import org.onosproject.cordvtn.OvsdbNode;
-import org.onosproject.net.DeviceId;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-/**
- * Adds a new OVSDB nodes.
- */
-@Command(scope = "onos", name = "ovsdb-add",
- description = "Adds a new OVSDB node to cordvtn")
-public class OvsdbNodeAddCommand extends AbstractShellCommand {
-
- @Argument(index = 0, name = "host", description = "Hostname or IP",
- required = true, multiValued = false)
- private String host = null;
-
- @Argument(index = 1, name = "address",
- description = "OVSDB server listening address (ip:port)",
- required = true, multiValued = false)
- private String address = 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(address.contains(":"), "address should be ip:port format");
- checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format");
-
- CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
- String[] ipPort = address.split(":");
- OvsdbNode ovsdb = new DefaultOvsdbNode(host,
- IpAddress.valueOf(ipPort[0]),
- TpPort.tpPort(Integer.parseInt(ipPort[1])),
- DeviceId.deviceId(bridgeId));
- service.addNode(ovsdb);
- }
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java
deleted file mode 100644
index e4ca0f3c..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java
+++ /dev/null
@@ -1,60 +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.OvsdbNode;
-
-import java.util.NoSuchElementException;
-
-/**
- * Connects to OVSDBs.
- */
-@Command(scope = "onos", name = "ovsdb-connect",
- description = "Connects to OVSDBs")
-public class OvsdbNodeConnectCommand extends AbstractShellCommand {
-
- @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)",
- required = true, multiValued = true)
- private String[] hosts = null;
-
- @Override
- protected void execute() {
- CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
-
- for (String host : hosts) {
- OvsdbNode ovsdb;
- try {
- ovsdb = service.getNodes().stream()
- .filter(node -> node.host().equals(host))
- .findFirst().get();
- } catch (NoSuchElementException e) {
- print("Unable to find %s", host);
- continue;
- }
-
- if (service.isNodeConnected(ovsdb)) {
- print("OVSDB %s is already in connected state, do nothing", host);
- } else {
- service.connect(ovsdb);
- }
- }
- }
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.java
deleted file mode 100644
index a500d0d8..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.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.OvsdbNode;
-
-import java.util.NoSuchElementException;
-
-/**
- * Deletes OVSDB nodes from cordvtn.
- */
-@Command(scope = "onos", name = "ovsdb-delete",
- description = "Deletes OVSDB nodes from cordvtn")
-public class OvsdbNodeDeleteCommand extends AbstractShellCommand {
-
- @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)",
- required = true, multiValued = true)
- private String[] hosts = null;
-
- @Override
- protected void execute() {
- CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
-
- for (String host : hosts) {
- OvsdbNode ovsdb;
- try {
- ovsdb = service.getNodes().stream()
- .filter(node -> node.host().equals(host))
- .findFirst().get();
-
- } catch (NoSuchElementException e) {
- print("Unable to find %s", host);
- continue;
- }
-
- service.deleteNode(ovsdb);
- }
- }
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java
deleted file mode 100644
index 14e44e08..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java
+++ /dev/null
@@ -1,60 +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.OvsdbNode;
-
-import java.util.NoSuchElementException;
-
-/**
- * Disconnects OVSDBs.
- */
-@Command(scope = "onos", name = "ovsdb-disconnect",
- description = "Disconnects OVSDBs")
-public class OvsdbNodeDisconnectCommand extends AbstractShellCommand {
-
- @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)",
- required = true, multiValued = true)
- private String[] hosts = null;
-
- @Override
- protected void execute() {
- CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
-
- for (String host : hosts) {
- OvsdbNode ovsdb;
- try {
- ovsdb = service.getNodes().stream()
- .filter(node -> node.host().equals(host))
- .findFirst().get();
- } catch (NoSuchElementException e) {
- print("Unable to find %s", host);
- continue;
- }
-
- if (!service.isNodeConnected(ovsdb)) {
- print("OVSDB %s is already in disconnected state, do nothing", host);
- } else {
- service.disconnect(ovsdb);
- }
- }
- }
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.java
deleted file mode 100644
index 7d125ca6..00000000
--- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.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.OvsdbNode;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Lists all OVSDB nodes.
- */
-@Command(scope = "onos", name = "ovsdbs",
- description = "Lists all OVSDB nodes registered in cordvtn application")
-public class OvsdbNodeListCommand extends AbstractShellCommand {
-
- @Override
- protected void execute() {
- CordVtnService service = AbstractShellCommand.get(CordVtnService.class);
- List<OvsdbNode> ovsdbs = service.getNodes();
- Collections.sort(ovsdbs, OvsdbNode.OVSDB_NODE_COMPARATOR);
-
- if (outputJson()) {
- print("%s", json(service, ovsdbs));
- } else {
- for (OvsdbNode ovsdb : ovsdbs) {
- print("host=%s, address=%s, br-int=%s, state=%s",
- ovsdb.host(),
- ovsdb.ip().toString() + ":" + ovsdb.port().toString(),
- ovsdb.intBrId().toString(),
- getState(service, ovsdb));
- }
- print("Total %s nodes", service.getNodeCount());
- }
- }
-
- private JsonNode json(CordVtnService service, List<OvsdbNode> ovsdbs) {
- ObjectMapper mapper = new ObjectMapper();
- ArrayNode result = mapper.createArrayNode();
- for (OvsdbNode ovsdb : ovsdbs) {
- String ipPort = ovsdb.ip().toString() + ":" + ovsdb.port().toString();
- result.add(mapper.createObjectNode()
- .put("host", ovsdb.host())
- .put("address", ipPort)
- .put("brInt", ovsdb.intBrId().toString())
- .put("state", getState(service, ovsdb)));
- }
- return result;
- }
-
- private String getState(CordVtnService service, OvsdbNode ovsdb) {
- return service.isNodeConnected(ovsdb) ? "CONNECTED" : "DISCONNECTED";
- }
-}
diff --git a/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 6e172387..ad28bc75 100644
--- a/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -17,19 +17,16 @@
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
- <action class="org.onosproject.cordvtn.cli.OvsdbNodeListCommand"/>
+ <action class="org.onosproject.cordvtn.cli.CordVtnNodeListCommand"/>
</command>
<command>
- <action class="org.onosproject.cordvtn.cli.OvsdbNodeAddCommand"/>
+ <action class="org.onosproject.cordvtn.cli.CordVtnNodeAddCommand"/>
</command>
<command>
- <action class="org.onosproject.cordvtn.cli.OvsdbNodeDeleteCommand"/>
+ <action class="org.onosproject.cordvtn.cli.CordVtnNodeDeleteCommand"/>
</command>
<command>
- <action class="org.onosproject.cordvtn.cli.OvsdbNodeConnectCommand"/>
- </command>
- <command>
- <action class="org.onosproject.cordvtn.cli.OvsdbNodeDisconnectCommand"/>
+ <action class="org.onosproject.cordvtn.cli.CordVtnNodeInitCommand"/>
</command>
</command-bundle>
</blueprint>
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
index e356c38b..ae610239 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java
@@ -58,15 +58,15 @@ public interface DhcpService {
/**
* Registers a static IP mapping with the DHCP Server.
- * Supports the request from OpenStack
+ * Supports rangeNotEnforced option
*
* @param macID macID of the client
* @param ipAddress IP Address requested for the client
- * @param fromOpenStack true if the request is from OpenStack
- * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack
+ * @param rangeNotEnforced true if rangeNotEnforced was set and the mapping will be eternal
+ * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set
* @return true if the mapping was successfully added, false otherwise
*/
- boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack,
+ boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced,
List<Ip4Address> addressList);
/**
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
index bd2e16b3..cdfadf7b 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java
@@ -52,12 +52,11 @@ public interface DhcpStore {
* @param hostId Host Id of the client requesting an IP
* @param ipAddr IP Address being requested
* @param leaseTime Lease time offered by the server for this mapping
- * @param fromOpenStack true if the request is from Openstack
- * @param addressList subnetMask, DHCP IP Address, Router IP Address, Domain Server IP Address if the request
- * from OpenStack
+ * @param rangeNotEnforced true if rangeNotEnforced was set
+ * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set
* @return returns true if the assignment was successful, false otherwise
*/
- boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced,
List<Ip4Address> addressList);
@@ -95,11 +94,11 @@ public interface DhcpStore {
*
* @param macID macID of the client
* @param ipAddr IP Address requested for the client
- * @param fromOpenStack true if the request is from Openstack
- * @param addressList subnetMask, DHCP/Router/Domain Server IP Address if the request from OpenStack
+ * @param rangeNotEnforced true if rangeNotEnforced was set
+ * @param addressList subnetMask, DHCP/Router/DNS IP Addresses rangeNotEnforced was set
* @return true if the mapping was successfully registered, false otherwise
*/
- boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack, List<Ip4Address> addressList);
+ boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced, List<Ip4Address> addressList);
/**
* Removes a static IP mapping associated with the given MAC ID from the DHCP Server.
diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
index 998579e2..5610fec8 100644
--- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
+++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java
@@ -41,7 +41,7 @@ public final class IpAssignment {
private final Ip4Address domainServer;
- private final boolean fromOpenStack;
+ private final boolean rangeNotEnforced;
private final AssignmentStatus assignmentStatus;
@@ -54,7 +54,7 @@ public final class IpAssignment {
/**
* IP Assignment has been requested by a OpenStack.
*/
- Option_Requested_From_OpenStack,
+ Option_RangeNotEnforced,
/**
* IP has been assigned to a host.
*/
@@ -78,13 +78,13 @@ public final class IpAssignment {
* @param dhcpServer
* @param routerAddress
* @param domainServer
- * @param fromOpenStack
+ * @param rangeNotEnforced
*/
private IpAssignment(Ip4Address ipAddress,
long leasePeriod,
Date timestamp,
AssignmentStatus assignmentStatus, Ip4Address subnetMask, Ip4Address dhcpServer,
- Ip4Address routerAddress, Ip4Address domainServer, boolean fromOpenStack) {
+ Ip4Address routerAddress, Ip4Address domainServer, boolean rangeNotEnforced) {
this.ipAddress = ipAddress;
this.leasePeriod = leasePeriod;
this.timestamp = timestamp;
@@ -93,7 +93,7 @@ public final class IpAssignment {
this.dhcpServer = dhcpServer;
this.routerAddress = routerAddress;
this.domainServer = domainServer;
- this.fromOpenStack = fromOpenStack;
+ this.rangeNotEnforced = rangeNotEnforced;
}
/**
@@ -157,8 +157,8 @@ public final class IpAssignment {
return domainServer;
}
- public boolean fromOpenStack() {
- return fromOpenStack;
+ public boolean rangeNotEnforced() {
+ return rangeNotEnforced;
}
@Override
@@ -172,7 +172,7 @@ public final class IpAssignment {
.add("dhcpServer", dhcpServer)
.add("routerAddress", routerAddress)
.add("domainServer", domainServer)
- .add("fromOpenStack", fromOpenStack)
+ .add("rangeNotEnforced", rangeNotEnforced)
.toString();
}
@@ -216,7 +216,7 @@ public final class IpAssignment {
private Ip4Address routerAddress;
- private boolean fromOpenStack = false;
+ private boolean rangeNotEnforced = false;
private Builder() {
@@ -232,7 +232,7 @@ public final class IpAssignment {
public IpAssignment build() {
validateInputs();
return new IpAssignment(ipAddress, leasePeriod, timeStamp, assignmentStatus, subnetMask,
- dhcpServer, domainServer, routerAddress, fromOpenStack);
+ dhcpServer, domainServer, routerAddress, rangeNotEnforced);
}
public Builder ipAddress(Ip4Address addr) {
@@ -275,8 +275,8 @@ public final class IpAssignment {
return this;
}
- public Builder fromOpenStack(boolean fromOpenStack) {
- this.fromOpenStack = fromOpenStack;
+ public Builder rangeNotEnforced(boolean rangeNotEnforced) {
+ this.rangeNotEnforced = rangeNotEnforced;
return this;
}
@@ -287,16 +287,16 @@ public final class IpAssignment {
checkNotNull(leasePeriod, "Lease Period must be specified");
checkNotNull(timeStamp, "Timestamp must be specified");
- if (fromOpenStack) {
- checkNotNull(subnetMask, "subnetMask must be specified in case of OpenStack");
- checkNotNull(dhcpServer, "dhcpServer must be specified in case of OpenStack");
- checkNotNull(domainServer, "domainServer must be specified in case of OpenStack");
- checkNotNull(routerAddress, "routerAddress must be specified in case of OpenStack");
+ if (rangeNotEnforced) {
+ checkNotNull(subnetMask, "subnetMask must be specified in case of rangeNotEnforced");
+ checkNotNull(dhcpServer, "dhcpServer must be specified in case of rangeNotEnforced");
+ checkNotNull(domainServer, "domainServer must be specified in case of rangeNotEnforced");
+ checkNotNull(routerAddress, "routerAddress must be specified in case of rangeNotEnforced");
}
switch (assignmentStatus) {
case Option_Requested:
- case Option_Requested_From_OpenStack:
+ case Option_RangeNotEnforced:
case Option_Assigned:
case Option_Expired:
break;
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java
index 4353d623..1efdd082 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java
@@ -21,6 +21,9 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
import org.onosproject.net.config.basics.BasicElementConfig;
+import static org.onosproject.net.config.Config.FieldPresence.MANDATORY;
+import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL;
+
/**
* DHCP Config class.
*/
@@ -43,6 +46,20 @@ public class DhcpConfig extends Config<ApplicationId> {
public static final int DEFAULT = -1;
+ @Override
+ public boolean isValid() {
+ // FIXME: Sweep through and revisit the validation assertions
+ // For now, this is just a demonstration of potential uses
+ return hasOnlyFields(MY_IP, MY_MAC, SUBNET_MASK, BROADCAST_ADDRESS,
+ ROUTER_ADDRESS, DOMAIN_SERVER, TTL, LEASE_TIME,
+ RENEW_TIME, REBIND_TIME, TIMER_DELAY, DEFAULT_TIMEOUT,
+ START_IP, END_IP) &&
+ isIpAddress(MY_IP, MANDATORY) && isMacAddress(MY_MAC, MANDATORY) &&
+ isIpAddress(START_IP, MANDATORY) && isIpAddress(END_IP, MANDATORY) &&
+ isNumber(LEASE_TIME, OPTIONAL, 1) && isNumber(REBIND_TIME, OPTIONAL, 1) &&
+ isNumber(DEFAULT_TIMEOUT, OPTIONAL, 1, 3600);
+ }
+
/**
* Returns the dhcp server ip.
*
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
index 4093f2d2..a1707e0b 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java
@@ -109,7 +109,7 @@ public class DhcpManager implements DhcpService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
- private DHCPPacketProcessor processor = new DHCPPacketProcessor();
+ private DhcpPacketProcessor processor = new DhcpPacketProcessor();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@@ -241,12 +241,12 @@ public class DhcpManager implements DhcpService {
}
@Override
- public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean fromOpenStack,
+ public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced,
List<Ip4Address> addressList) {
log.debug("setStaticMapping is called with Mac: {}, Ip: {} addressList: {}",
macID.toString(), ipAddress.toString(), addressList.toString());
- return dhcpStore.assignStaticIP(macID, ipAddress, fromOpenStack, addressList);
+ return dhcpStore.assignStaticIP(macID, ipAddress, rangeNotEnforced, addressList);
}
@Override
@@ -259,7 +259,7 @@ public class DhcpManager implements DhcpService {
return dhcpStore.getAvailableIPs();
}
- private class DHCPPacketProcessor implements PacketProcessor {
+ private class DhcpPacketProcessor implements PacketProcessor {
/**
* Builds the DHCP Reply packet.
@@ -279,7 +279,7 @@ public class DhcpManager implements DhcpService {
ipAssignment = dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(packet.getSourceMAC()));
- if (ipAssignment != null && ipAssignment.fromOpenStack()) {
+ if (ipAssignment != null && ipAssignment.rangeNotEnforced()) {
subnetMaskReply = ipAssignment.subnetMask();
dhcpServerReply = ipAssignment.dhcpServer();
domainServerReply = ipAssignment.domainServer();
@@ -437,7 +437,7 @@ public class DhcpManager implements DhcpService {
* @param context context of the incoming message
* @param dhcpPayload the extracted DHCP payload
*/
- private void processDHCPPacket(PacketContext context, DHCP dhcpPayload) {
+ private void processDhcpPacket(PacketContext context, DHCP dhcpPayload) {
Ethernet packet = context.inPacket().parsed();
boolean flagIfRequestedIP = false;
boolean flagIfServerIP = false;
@@ -464,9 +464,9 @@ public class DhcpManager implements DhcpService {
}
}
DHCPPacketType outgoingPacketType;
- MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress());
+ MacAddress clientMac = new MacAddress(dhcpPayload.getClientHardwareAddress());
VlanId vlanId = VlanId.vlanId(packet.getVlanID());
- HostId hostId = HostId.hostId(clientMAC, vlanId);
+ HostId hostId = HostId.hostId(clientMac, vlanId);
if (incomingPacketType.getValue() == DHCPPacketType.DHCPDISCOVER.getValue()) {
@@ -484,8 +484,9 @@ public class DhcpManager implements DhcpService {
if (flagIfServerIP && flagIfRequestedIP) {
// SELECTING state
- if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMAC))
- .fromOpenStack()) {
+
+ if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMac))
+ .rangeNotEnforced()) {
outgoingPacketType = DHCPPacketType.DHCPACK;
Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue());
sendReply(context, ethReply);
@@ -544,7 +545,7 @@ public class DhcpManager implements DhcpService {
* @param context context of the incoming message
* @param packet the ethernet payload
*/
- private void processARPPacket(PacketContext context, Ethernet packet) {
+ private void processArpPacket(PacketContext context, Ethernet packet) {
ARP arpPacket = (ARP) packet.getPayload();
@@ -605,7 +606,7 @@ public class DhcpManager implements DhcpService {
// This is meant for the dhcp server so process the packet here.
DHCP dhcpPayload = (DHCP) udpPacket.getPayload();
- processDHCPPacket(context, dhcpPayload);
+ processDhcpPacket(context, dhcpPayload);
}
}
} else if (packet.getEtherType() == Ethernet.TYPE_ARP) {
@@ -614,7 +615,7 @@ public class DhcpManager implements DhcpService {
if ((arpPacket.getOpCode() == ARP.OP_REQUEST) &&
Objects.equals(myIP, Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()))) {
- processARPPacket(context, packet);
+ processArpPacket(context, packet);
}
}
@@ -727,4 +728,4 @@ public class DhcpManager implements DhcpService {
timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES);
}
}
-} \ No newline at end of file
+}
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
index 0f25495e..ad4522cb 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
+++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java
@@ -106,7 +106,7 @@ public class DistributedDhcpStore implements DhcpStore {
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
Ip4Address ipAddr = assignmentInfo.ipAddress();
- if (assignmentInfo.fromOpenStack()) {
+ if (assignmentInfo.rangeNotEnforced()) {
return assignmentInfo.ipAddress();
} else if (status == IpAssignment.AssignmentStatus.Option_Assigned ||
status == IpAssignment.AssignmentStatus.Option_Requested) {
@@ -163,12 +163,15 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack,
+ public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced,
List<Ip4Address> addressList) {
IpAssignment assignmentInfo;
+ log.debug("Assign IP Called w/ Ip4Address: {}, HostId: {}", ipAddr.toString(), hostId.mac().toString());
+
if (allocationMap.containsKey(hostId)) {
+
assignmentInfo = allocationMap.get(hostId).value();
IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus();
@@ -212,17 +215,17 @@ public class DistributedDhcpStore implements DhcpStore {
allocationMap.put(hostId, assignmentInfo);
return true;
}
- } else if (fromOpenStack) {
+ } else if (rangeNotEnforced) {
assignmentInfo = IpAssignment.builder()
.ipAddress(ipAddr)
.timestamp(new Date())
.leasePeriod(leaseTime)
- .fromOpenStack(true)
- .assignmentStatus(IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack)
+ .rangeNotEnforced(true)
+ .assignmentStatus(IpAssignment.AssignmentStatus.Option_RangeNotEnforced)
.subnetMask((Ip4Address) addressList.toArray()[0])
.dhcpServer((Ip4Address) addressList.toArray()[1])
- .domainServer((Ip4Address) addressList.toArray()[2])
- .routerAddress((Ip4Address) addressList.toArray()[3])
+ .routerAddress((Ip4Address) addressList.toArray()[2])
+ .domainServer((Ip4Address) addressList.toArray()[3])
.build();
allocationMap.put(hostId, assignmentInfo);
return true;
@@ -259,7 +262,7 @@ public class DistributedDhcpStore implements DhcpStore {
for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) {
assignment = entry.getValue().value();
if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned
- || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Requested_From_OpenStack) {
+ || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_RangeNotEnforced) {
validMapping.put(entry.getKey(), assignment);
}
}
@@ -276,10 +279,10 @@ public class DistributedDhcpStore implements DhcpStore {
}
@Override
- public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack,
+ public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced,
List<Ip4Address> addressList) {
HostId host = HostId.hostId(macID);
- return assignIP(host, ipAddr, -1, fromOpenStack, addressList);
+ return assignIP(host, ipAddr, -1, rangeNotEnforced, addressList);
}
@Override
@@ -287,6 +290,12 @@ public class DistributedDhcpStore implements DhcpStore {
HostId host = HostId.hostId(macID);
if (allocationMap.containsKey(host)) {
IpAssignment assignment = allocationMap.get(host).value();
+
+ if (assignment.rangeNotEnforced()) {
+ allocationMap.remove(host);
+ return true;
+ }
+
Ip4Address freeIP = assignment.ipAddress();
if (assignment.leasePeriod() < 0) {
allocationMap.remove(host);
diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
deleted file mode 100644
index 7a078df9..00000000
--- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java
+++ /dev/null
@@ -1,165 +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.dhcp.rest;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.Lists;
-import org.onlab.packet.Ip4Address;
-import org.onlab.packet.MacAddress;
-import org.onosproject.dhcp.DhcpService;
-import org.onosproject.dhcp.IpAssignment;
-import org.onosproject.net.HostId;
-import org.onosproject.rest.AbstractWebResource;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-
-/**
- * Manage DHCP address assignments.
- */
-@Path("dhcp")
-public class DHCPWebResource extends AbstractWebResource {
-
- final DhcpService service = get(DhcpService.class);
-
- /**
- * Get DHCP server configuration data.
- * Shows lease, renewal and rebinding times in seconds.
- *
- * @return 200 OK
- */
- @GET
- @Path("config")
- public Response getConfigs() {
- DhcpService service = get(DhcpService.class);
- ObjectNode node = mapper().createObjectNode()
- .put("leaseTime", service.getLeaseTime())
- .put("renewalTime", service.getRenewalTime())
- .put("rebindingTime", service.getRebindingTime());
- return ok(node.toString()).build();
- }
-
- /**
- * Get all MAC/IP mappings.
- * Shows all MAC/IP mappings held by the DHCP server.
- *
- * @return 200 OK
- */
- @GET
- @Path("mappings")
- public Response listMappings() {
- ObjectNode root = mapper().createObjectNode();
-
- final Map<HostId, IpAssignment> intents = service.listMapping();
- ArrayNode arrayNode = root.putArray("mappings");
- intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
- .put("host", i.getKey().toString())
- .put("ip", i.getValue().ipAddress().toString())));
-
- return ok(root.toString()).build();
- }
-
-
-
- /**
- * Get all available IPs.
- * Shows all the IPs in the free pool of the DHCP Server.
- *
- * @return 200 OK
- */
- @GET
- @Path("available")
- public Response listAvailableIPs() {
- final Iterable<Ip4Address> availableIPList = service.getAvailableIPs();
-
- final ObjectNode root = mapper().createObjectNode();
- ArrayNode arrayNode = root.putArray("availableIP");
- availableIPList.forEach(i -> arrayNode.add(i.toString()));
- return ok(root.toString()).build();
- }
-
- /**
- * Post a new static MAC/IP binding.
- * Registers a static binding to the DHCP server, and displays the current set of bindings.
- *
- * @param stream JSON stream
- * @return 200 OK
- */
- @POST
- @Path("mappings")
- @Consumes(MediaType.APPLICATION_JSON)
- public Response setMapping(InputStream stream) {
- ObjectNode root = mapper().createObjectNode();
-
- try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
- JsonNode macID = jsonTree.get("mac");
- JsonNode ip = jsonTree.get("ip");
- if (macID != null && ip != null) {
-
- if (!service.setStaticMapping(MacAddress.valueOf(macID.asText()),
- Ip4Address.valueOf(ip.asText()), false, Lists.newArrayList())) {
- throw new IllegalArgumentException("Static Mapping Failed. The IP maybe unavailable.");
- }
- }
-
- final Map<HostId, IpAssignment> intents = service.listMapping();
- ArrayNode arrayNode = root.putArray("mappings");
- intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
- .put("host", i.getKey().toString())
- .put("ip", i.getValue().ipAddress().toString())));
- } catch (IOException e) {
- throw new IllegalArgumentException(e.getMessage());
- }
- return ok(root.toString()).build();
- }
-
- /**
- * Delete a static MAC/IP binding.
- * Removes a static binding from the DHCP Server, and displays the current set of bindings.
- *
- * @param macID mac address identifier
- * @return 200 OK
- */
- @DELETE
- @Path("mappings/{macID}")
- public Response deleteMapping(@PathParam("macID") String macID) {
-
- ObjectNode root = mapper().createObjectNode();
-
- if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
- throw new IllegalArgumentException("Static Mapping Removal Failed.");
- }
- final Map<HostId, IpAssignment> intents = service.listMapping();
- ArrayNode arrayNode = root.putArray("mappings");
- intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
- .put("host", i.getKey().toString())
- .put("ip", i.getValue().ipAddress().toString())));
-
- return ok(root.toString()).build();
- }
-}
diff --git a/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
index 27504548..a53110ee 100644
--- a/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
+++ b/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml
@@ -30,7 +30,7 @@
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>
- org.onosproject.dhcp.rest.DHCPWebResource
+ org.onosproject.dhcp.rest.DhcpWebResource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
diff --git a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
index bb6b74cc..e9b02608 100644
--- a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
+++ b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java
@@ -106,7 +106,7 @@ public class DhcpManagerTest {
*/
@Test
public void testDiscover() {
- Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPDISCOVER);
+ Ethernet reply = constructDhcpPacket(DHCPPacketType.DHCPDISCOVER);
sendPacket(reply);
}
@@ -115,7 +115,7 @@ public class DhcpManagerTest {
*/
@Test
public void testRequest() {
- Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPREQUEST);
+ Ethernet reply = constructDhcpPacket(DHCPPacketType.DHCPREQUEST);
sendPacket(reply);
}
@@ -138,7 +138,7 @@ public class DhcpManagerTest {
* @param packetType DHCP Message Type
* @return Ethernet packet
*/
- private Ethernet constructDHCPPacket(DHCPPacketType packetType) {
+ private Ethernet constructDhcpPacket(DHCPPacketType packetType) {
// Ethernet Frame.
Ethernet ethReply = new Ethernet();
diff --git a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java b/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java
deleted file mode 100644
index d5d7d277..00000000
--- a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * Copyright 2014 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.olt;
-
-import com.google.common.base.Strings;
-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.apache.felix.scr.annotations.Service;
-import org.onlab.packet.VlanId;
-import org.onlab.util.Tools;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Port;
-import org.onosproject.net.PortNumber;
-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.basics.SubjectFactories;
-import org.onosproject.net.device.DeviceEvent;
-import org.onosproject.net.device.DeviceListener;
-import org.onosproject.net.device.DeviceService;
-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.flowobjective.DefaultForwardingObjective;
-import org.onosproject.net.flowobjective.FlowObjectiveService;
-import org.onosproject.net.flowobjective.ForwardingObjective;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-
-import java.util.Dictionary;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Provisions rules on access devices.
- */
-@Service
-@Component(immediate = true)
-public class OLT implements AccessDeviceService {
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowObjectiveService flowObjectiveService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected NetworkConfigRegistry networkConfig;
-
- private final DeviceListener deviceListener = new InternalDeviceListener();
-
- private ApplicationId appId;
-
- private static final VlanId DEFAULT_VLAN = VlanId.vlanId((short) 0);
- public static final int OFFSET = 200;
-
- public static final int UPLINK_PORT = 129;
- public static final int GFAST_UPLINK_PORT = 100;
-
- public static final String OLT_DEVICE = "of:90e2ba82f97791e9";
- public static final String GFAST_DEVICE = "of:0011223344551357";
-
- @Property(name = "uplinkPort", intValue = UPLINK_PORT,
- label = "The OLT's uplink port number")
- private int uplinkPort = UPLINK_PORT;
-
- @Property(name = "gfastUplink", intValue = GFAST_UPLINK_PORT,
- label = "The OLT's uplink port number")
- private int gfastUplink = GFAST_UPLINK_PORT;
-
- //TODO: replace this with an annotation lookup
- @Property(name = "oltDevice", value = OLT_DEVICE,
- label = "The OLT device id")
- private String oltDevice = OLT_DEVICE;
-
- @Property(name = "gfastDevice", value = GFAST_DEVICE,
- label = "The gfast device id")
- private String gfastDevice = GFAST_DEVICE;
-
- private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
-
- private InternalNetworkConfigListener configListener =
- new InternalNetworkConfigListener();
- private static final Class<AccessDeviceConfig> CONFIG_CLASS =
- AccessDeviceConfig.class;
-
- private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory =
- new ConfigFactory<DeviceId, AccessDeviceConfig>(
- SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") {
- @Override
- public AccessDeviceConfig createConfig() {
- return new AccessDeviceConfig();
- }
- };
-
- @Activate
- public void activate() {
- appId = coreService.registerApplication("org.onosproject.olt");
-
- networkConfig.registerConfigFactory(configFactory);
- networkConfig.addListener(configListener);
-
- networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach(
- subject -> {
- AccessDeviceConfig config = networkConfig.getConfig(subject, AccessDeviceConfig.class);
- if (config != null) {
- AccessDeviceData data = config.getOlt();
- oltData.put(data.deviceId(), data);
- }
- }
- );
-
- /*deviceService.addListener(deviceListener);
-
- deviceService.getPorts(DeviceId.deviceId(oltDevice)).stream().forEach(
- port -> {
- if (!port.number().isLogical() && port.isEnabled()) {
- short vlanId = fetchVlanId(port.number());
- if (vlanId > 0) {
- provisionVlanOnPort(oltDevice, uplinkPort, port.number(), (short) 7);
- provisionVlanOnPort(oltDevice, uplinkPort, port.number(), vlanId);
- }
- }
- }
- );*/
-
-
- deviceService.getPorts(DeviceId.deviceId(gfastDevice)).stream()
- .filter(port -> !port.number().isLogical())
- .filter(Port::isEnabled)
- .forEach(port -> {
- short vlanId = (short) (fetchVlanId(port.number()) + OFFSET);
- if (vlanId > 0) {
- provisionVlanOnPort(gfastDevice, gfastUplink, port.number(), vlanId);
- }
- }
- );
- log.info("Started with Application ID {}", appId.id());
- }
-
- @Deactivate
- public void deactivate() {
- networkConfig.removeListener(configListener);
- networkConfig.unregisterConfigFactory(configFactory);
- log.info("Stopped");
- }
-
- @Modified
- public void modified(ComponentContext context) {
- Dictionary<?, ?> properties = context.getProperties();
-
- String s = Tools.get(properties, "uplinkPort");
- uplinkPort = Strings.isNullOrEmpty(s) ? UPLINK_PORT : Integer.parseInt(s);
-
- s = Tools.get(properties, "oltDevice");
- oltDevice = Strings.isNullOrEmpty(s) ? OLT_DEVICE : s;
- }
-
- private short fetchVlanId(PortNumber port) {
- long p = port.toLong() + OFFSET;
- if (p > 4095) {
- log.warn("Port Number {} exceeds vlan max", port);
- return -1;
- }
- return (short) p;
- }
-
- private void provisionVlanOnPort(String deviceId, int uplinkPort, PortNumber p, short vlanId) {
- DeviceId did = DeviceId.deviceId(deviceId);
-
- TrafficSelector upstream = DefaultTrafficSelector.builder()
- .matchVlanId(VlanId.vlanId(vlanId))
- .matchInPort(p)
- .build();
-
- TrafficSelector downStream = DefaultTrafficSelector.builder()
- .matchVlanId(VlanId.vlanId(vlanId))
- .matchInPort(PortNumber.portNumber(uplinkPort))
- .build();
-
- TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
- .setOutput(PortNumber.portNumber(uplinkPort))
- .build();
-
- TrafficTreatment downStreamTreatment = DefaultTrafficTreatment.builder()
- .setOutput(p)
- .build();
-
-
- ForwardingObjective upFwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(1000)
- .makePermanent()
- .withSelector(upstream)
- .fromApp(appId)
- .withTreatment(upstreamTreatment)
- .add();
-
- ForwardingObjective downFwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(1000)
- .makePermanent()
- .withSelector(downStream)
- .fromApp(appId)
- .withTreatment(downStreamTreatment)
- .add();
-
- flowObjectiveService.forward(did, upFwd);
- flowObjectiveService.forward(did, downFwd);
- }
-
- @Override
- public void provisionSubscriber(ConnectPoint port, VlanId vlan) {
- AccessDeviceData olt = oltData.get(port.deviceId());
-
- if (olt == null) {
- log.warn("No data found for OLT device {}", port.deviceId());
- return;
- }
-
- provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(),
- olt.defaultVlan());
- }
-
- private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort,
- PortNumber subscriberPort,
- VlanId subscriberVlan, VlanId deviceVlan,
- Optional<VlanId> defaultVlan) {
-
- TrafficSelector upstream = DefaultTrafficSelector.builder()
- .matchVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN)
- .matchInPort(subscriberPort)
- .build();
-
- TrafficSelector downstream = DefaultTrafficSelector.builder()
- .matchVlanId(deviceVlan)
- .matchInPort(uplinkPort)
- .build();
-
- TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
- .setVlanId(subscriberVlan)
- .pushVlan()
- .setVlanId(deviceVlan)
- .setOutput(uplinkPort)
- .build();
-
- TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
- .popVlan()
- .setVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN)
- .setOutput(subscriberPort)
- .build();
-
-
- ForwardingObjective upFwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(1000)
- .makePermanent()
- .withSelector(upstream)
- .fromApp(appId)
- .withTreatment(upstreamTreatment)
- .add();
-
- ForwardingObjective downFwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(1000)
- .makePermanent()
- .withSelector(downstream)
- .fromApp(appId)
- .withTreatment(downstreamTreatment)
- .add();
-
- flowObjectiveService.forward(deviceId, upFwd);
- flowObjectiveService.forward(deviceId, downFwd);
- }
-
- @Override
- public void removeSubscriber(ConnectPoint port) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- private class InternalDeviceListener implements DeviceListener {
- @Override
- public void event(DeviceEvent event) {
- DeviceId devId = DeviceId.deviceId(oltDevice);
- switch (event.type()) {
- case PORT_ADDED:
- case PORT_UPDATED:
- if (devId.equals(event.subject().id()) && event.port().isEnabled()) {
- short vlanId = fetchVlanId(event.port().number());
- provisionVlanOnPort(gfastDevice, uplinkPort, event.port().number(), vlanId);
- }
- break;
- case DEVICE_ADDED:
- case DEVICE_UPDATED:
- case DEVICE_REMOVED:
- case DEVICE_SUSPENDED:
- case DEVICE_AVAILABILITY_CHANGED:
- case PORT_REMOVED:
- case PORT_STATS_UPDATED:
- default:
- return;
- }
- }
- }
-
- private class InternalNetworkConfigListener implements NetworkConfigListener {
- @Override
- public void event(NetworkConfigEvent event) {
- switch (event.type()) {
-
- case CONFIG_ADDED:
- case CONFIG_UPDATED:
- if (event.configClass().equals(CONFIG_CLASS)) {
- AccessDeviceConfig config =
- networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
- if (config != null) {
- oltData.put(config.getOlt().deviceId(), config.getOlt());
- }
- }
- break;
- case CONFIG_UNREGISTERED:
- case CONFIG_REMOVED:
- default:
- break;
- }
- }
- }
-
-}
diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java
index 661a873e..f6e98060 100644
--- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java
+++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java
@@ -120,7 +120,7 @@ public class OpenstackSwitchingRulePopulator {
*
* @param id device ID to set the rules
*/
- private void setFlowRuleForDHCP(DeviceId id) {
+ private void setFlowRuleForDhcp(DeviceId id) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
diff --git a/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java b/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
index e0545023..3890bb4a 100644
--- a/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
+++ b/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java
@@ -343,6 +343,7 @@ public class OpticalPathProvisioner {
return getIntents(crossConnectPoints);
}
+ log.warn("Unable to find multi-layer path.");
return Collections.emptyList();
}
@@ -392,20 +393,41 @@ public class OpticalPathProvisioner {
}
/**
- * Verifies if given link is cross-connect between packet and optical layer.
+ * Verifies if given device type is in packet layer, i.e., ROADM, OTN or ROADM_OTN device.
+ *
+ * @param type device type
+ * @return true if in packet layer, false otherwise
+ */
+ private boolean isPacketLayer(Device.Type type) {
+ return type == Device.Type.SWITCH || type == Device.Type.ROUTER;
+ }
+
+ /**
+ * Verifies if given device type is in packet layer, i.e., switch or router device.
+ *
+ * @param type device type
+ * @return true if in packet layer, false otherwise
+ */
+ private boolean isTransportLayer(Device.Type type) {
+ return type == Device.Type.ROADM || type == Device.Type.OTN || type == Device.Type.ROADM_OTN;
+ }
+
+ /**
+ * Verifies if given link forms a cross-connection between packet and optical layer.
*
* @param link the link
- * @return true if the link is a cross-connect link
+ * @return true if the link is a cross-connect link, false otherwise
*/
- public static boolean isCrossConnectLink(Link link) {
+ private boolean isCrossConnectLink(Link link) {
if (link.type() != Link.Type.OPTICAL) {
return false;
}
- checkNotNull(link.annotations());
- checkNotNull(link.annotations().value("optical.type"));
+ Device.Type src = deviceService.getDevice(link.src().deviceId()).type();
+ Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type();
- return link.annotations().value("optical.type").equals("cross-connect");
+ return src != dst &&
+ ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src)));
}
}
diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java
index 5b5a259e..1ccb6b6b 100644
--- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java
+++ b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java
@@ -309,94 +309,104 @@ final class BgpOpen {
case BgpConstants.Open.Capabilities.TYPE:
// Optional Parameter Type: Capabilities
if (paramLen < BgpConstants.Open.Capabilities.MIN_LENGTH) {
- // ERROR: Malformed Capability
- String errorMsg = "Malformed Capability Type " + paramType;
+ // ERROR: Malformed Param Type
+ String errorMsg = "Malformed Capabilities Optional "
+ + "Parameter Type " + paramType;
throw new BgpMessage.BgpParseException(errorMsg);
}
- int capabEnd = message.readerIndex() + paramLen;
- int capabCode = message.readUnsignedByte();
- int capabLen = message.readUnsignedByte();
- if (message.readerIndex() + capabLen > capabEnd) {
- // ERROR: Malformed Capability
- String errorMsg = "Malformed Capability Type " + paramType;
- throw new BgpMessage.BgpParseException(errorMsg);
- }
-
- switch (capabCode) {
- case BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE:
- // Multiprotocol Extensions Capabilities (RFC 4760)
- if (capabLen != BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH) {
- // ERROR: Multiprotocol Extension Length Error
- String errorMsg = "Multiprotocol Extension Length Error";
+ int paramEnd = message.readerIndex() + paramLen;
+ // Parse Capabilities
+ while (message.readerIndex() < paramEnd) {
+ if (paramEnd - message.readerIndex() <
+ BgpConstants.Open.Capabilities.MIN_LENGTH) {
+ String errorMsg = "Malformed Capabilities";
throw new BgpMessage.BgpParseException(errorMsg);
}
- // Decode the AFI (2 octets) and SAFI (1 octet)
- int afi = message.readUnsignedShort();
- int reserved = message.readUnsignedByte();
- int safi = message.readUnsignedByte();
- log.debug("BGP RX OPEN Capability: AFI = {} SAFI = {}",
- afi, safi);
- //
- // Setup the AFI/SAFI in the BgpSession
- //
- // NOTE: For now we just copy the remote AFI/SAFI setting
- // to the local configuration.
- //
- if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 &&
- safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) {
- bgpSession.remoteInfo().setIpv4Unicast();
- bgpSession.localInfo().setIpv4Unicast();
- } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 &&
- safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) {
- bgpSession.remoteInfo().setIpv4Multicast();
- bgpSession.localInfo().setIpv4Multicast();
- } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 &&
- safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) {
- bgpSession.remoteInfo().setIpv6Unicast();
- bgpSession.localInfo().setIpv6Unicast();
- } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 &&
- safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) {
- bgpSession.remoteInfo().setIpv6Multicast();
- bgpSession.localInfo().setIpv6Multicast();
- } else {
- log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}",
- afi, safi);
+ int capabCode = message.readUnsignedByte();
+ int capabLen = message.readUnsignedByte();
+ if (message.readerIndex() + capabLen > paramEnd) {
+ // ERROR: Malformed Capability
+ String errorMsg = "Malformed Capability instance with "
+ + "code " + capabCode;
+ throw new BgpMessage.BgpParseException(errorMsg);
}
- break;
- case BgpConstants.Open.Capabilities.As4Octet.CODE:
- // Support for 4-octet AS Number Capabilities (RFC 6793)
- if (capabLen != BgpConstants.Open.Capabilities.As4Octet.LENGTH) {
- // ERROR: 4-octet AS Number Capability Length Error
- String errorMsg = "4-octet AS Number Capability Length Error";
- throw new BgpMessage.BgpParseException(errorMsg);
+ switch (capabCode) {
+ case BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE:
+ // Multiprotocol Extensions Capabilities (RFC 4760)
+ if (capabLen != BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH) {
+ // ERROR: Multiprotocol Extension Length Error
+ String errorMsg = "Multiprotocol Extension Length Error";
+ throw new BgpMessage.BgpParseException(errorMsg);
+ }
+ // Decode the AFI (2 octets) and SAFI (1 octet)
+ int afi = message.readUnsignedShort();
+ int reserved = message.readUnsignedByte();
+ int safi = message.readUnsignedByte();
+ log.debug("BGP RX OPEN Capability: AFI = {} SAFI = {}",
+ afi, safi);
+ //
+ // Setup the AFI/SAFI in the BgpSession
+ //
+ // NOTE: For now we just copy the remote AFI/SAFI setting
+ // to the local configuration.
+ //
+ if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 &&
+ safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) {
+ bgpSession.remoteInfo().setIpv4Unicast();
+ bgpSession.localInfo().setIpv4Unicast();
+ } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 &&
+ safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) {
+ bgpSession.remoteInfo().setIpv4Multicast();
+ bgpSession.localInfo().setIpv4Multicast();
+ } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 &&
+ safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) {
+ bgpSession.remoteInfo().setIpv6Unicast();
+ bgpSession.localInfo().setIpv6Unicast();
+ } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 &&
+ safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) {
+ bgpSession.remoteInfo().setIpv6Multicast();
+ bgpSession.localInfo().setIpv6Multicast();
+ } else {
+ log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}",
+ afi, safi);
+ }
+ break;
+
+ case BgpConstants.Open.Capabilities.As4Octet.CODE:
+ // Support for 4-octet AS Number Capabilities (RFC 6793)
+ if (capabLen != BgpConstants.Open.Capabilities.As4Octet.LENGTH) {
+ // ERROR: 4-octet AS Number Capability Length Error
+ String errorMsg = "4-octet AS Number Capability Length Error";
+ throw new BgpMessage.BgpParseException(errorMsg);
+ }
+ long as4Number = message.readUnsignedInt();
+
+ bgpSession.remoteInfo().setAs4OctetCapability();
+ bgpSession.remoteInfo().setAs4Number(as4Number);
+
+ //
+ // Copy remote 4-octet AS Number Capabilities and AS
+ // Number. This is a temporary setting until local AS
+ // number configuration is supported.
+ //
+ bgpSession.localInfo().setAs4OctetCapability();
+ bgpSession.localInfo().setAs4Number(as4Number);
+ log.debug("BGP RX OPEN Capability: AS4 Number = {}",
+ as4Number);
+ break;
+
+ default:
+ // Unknown Capability: ignore it
+ log.debug("BGP RX OPEN Capability Code = {} Length = {}",
+ capabCode, capabLen);
+ message.readBytes(capabLen);
+ break;
}
- long as4Number = message.readUnsignedInt();
-
- bgpSession.remoteInfo().setAs4OctetCapability();
- bgpSession.remoteInfo().setAs4Number(as4Number);
-
- //
- // Copy remote 4-octet AS Number Capabilities and AS
- // Number. This is a temporary setting until local AS
- // number configuration is supported.
- //
- bgpSession.localInfo().setAs4OctetCapability();
- bgpSession.localInfo().setAs4Number(as4Number);
- log.debug("BGP RX OPEN Capability: AS4 Number = {}",
- as4Number);
- break;
-
- default:
- // Unknown Capability: ignore it
- log.debug("BGP RX OPEN Capability Code = {} Length = {}",
- capabCode, capabLen);
- message.readBytes(capabLen);
- break;
- }
- break;
+ }
+ break;
default:
// Unknown Parameter Type: ignore it
log.debug("BGP RX OPEN Parameter Type = {} Length = {}",
diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
index a3cd6875..2eb5d0f3 100644
--- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
+++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java
@@ -74,7 +74,7 @@ public class IntentSynchronizer implements IntentSynchronizationService {
* @param intentService the intent service
* @param executorService executor service for synchronization thread
*/
- IntentSynchronizer(ApplicationId appId, IntentService intentService,
+ public IntentSynchronizer(ApplicationId appId, IntentService intentService,
ExecutorService executorService) {
this.appId = appId;
this.intentService = intentService;
diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java
index 8e2a3df3..863de12a 100644
--- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java
+++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java
@@ -19,13 +19,12 @@ package org.onosproject.sdnip;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.net.intent.SinglePointToMultiPointIntent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects;
-import static com.google.common.base.Preconditions.checkArgument;
-
/**
* Utilities for dealing with intents.
*/
@@ -49,15 +48,24 @@ public final class IntentUtils {
* @return true if the two intents represent the same value, otherwise false
*/
public static boolean equals(Intent one, Intent two) {
- checkArgument(one.getClass() == two.getClass(),
- "Intents are not the same type");
+ if (one.getClass() != two.getClass()) {
+ return false;
+ }
if (!(Objects.equals(one.appId(), two.appId()) &&
Objects.equals(one.key(), two.key()))) {
return false;
}
- if (one instanceof MultiPointToSinglePointIntent) {
+ if (one instanceof SinglePointToMultiPointIntent) {
+ SinglePointToMultiPointIntent intent1 = (SinglePointToMultiPointIntent) one;
+ SinglePointToMultiPointIntent intent2 = (SinglePointToMultiPointIntent) two;
+
+ return Objects.equals(intent1.selector(), intent2.selector()) &&
+ Objects.equals(intent1.treatment(), intent2.treatment()) &&
+ Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) &&
+ Objects.equals(intent1.egressPoints(), intent2.egressPoints());
+ } else if (one instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one;
MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two;
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
index 96c85ba8..2c6412cf 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
@@ -20,10 +20,10 @@ import org.onlab.packet.Ethernet;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
-import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficTreatment;
@@ -60,12 +60,21 @@ public class ArpHandler {
/**
* Processes incoming ARP packets.
+ *
* If it is an ARP request to router itself or known hosts,
* then it sends ARP response.
* If it is an ARP request to unknown hosts in its own subnet,
* then it flood the ARP request to the ports.
* If it is an ARP response, then set a flow rule for the host
* and forward any IP packets to the host in the packet buffer to the host.
+ * <p>
+ * Note: We handles all ARP packet in, even for those ARP packets between
+ * hosts in the same subnet.
+ * For an ARP packet with broadcast destination MAC,
+ * some switches pipelines will send it to the controller due to table miss,
+ * other swithches will flood the packets directly in the data plane without
+ * packet in.
+ * We can deal with both cases.
*
* @param pkt incoming packet
*/
@@ -86,29 +95,56 @@ public class ArpHandler {
if (arp.getOpCode() == ARP.OP_REQUEST) {
handleArpRequest(deviceId, connectPoint, ethernet);
} else {
- srManager.ipHandler.forwardPackets(deviceId, hostIpAddress);
+ handleArpReply(deviceId, connectPoint, ethernet);
}
}
private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) {
ARP arpRequest = (ARP) payload.getPayload();
+ VlanId vlanId = VlanId.vlanId(payload.getVlanID());
HostId targetHostId = HostId.hostId(MacAddress.valueOf(
- arpRequest.getTargetHardwareAddress()));
+ arpRequest.getTargetHardwareAddress()),
+ vlanId);
- // ARP request for router
+ // ARP request for router. Send ARP reply.
if (isArpReqForRouter(deviceId, arpRequest)) {
Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress());
-
- sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress));
+ sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress), vlanId);
} else {
Host targetHost = srManager.hostService.getHost(targetHostId);
- // ARP request for known hosts
+ // ARP request for known hosts. Send proxy ARP reply on behalf of the target.
if (targetHost != null) {
- sendArpResponse(arpRequest, targetHost.mac());
+ removeVlanAndForward(payload, targetHost.location());
+ // ARP request for unknown host in the subnet. Flood in the subnet.
+ } else {
+ removeVlanAndFlood(payload, inPort);
+ }
+ }
+ }
- // ARP request for unknown host in the subnet
- } else if (isArpReqForSubnet(deviceId, arpRequest)) {
- flood(payload, inPort);
+ private void handleArpReply(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) {
+ ARP arpReply = (ARP) payload.getPayload();
+ VlanId vlanId = VlanId.vlanId(payload.getVlanID());
+ HostId targetHostId = HostId.hostId(MacAddress.valueOf(
+ arpReply.getTargetHardwareAddress()),
+ vlanId);
+
+ // ARP reply for router. Process all pending IP packets.
+ if (isArpReqForRouter(deviceId, arpReply)) {
+ Ip4Address hostIpAddress = Ip4Address.valueOf(arpReply.getSenderProtocolAddress());
+ srManager.ipHandler.forwardPackets(deviceId, hostIpAddress);
+ } else {
+ Host targetHost = srManager.hostService.getHost(targetHostId);
+ // ARP reply for known hosts. Forward to the host.
+ if (targetHost != null) {
+ removeVlanAndForward(payload, targetHost.location());
+ // ARP reply for unknown host, Flood in the subnet.
+ } else {
+ // Don't flood to non-edge ports
+ if (vlanId.equals(VlanId.vlanId(srManager.ASSIGNED_VLAN_NO_SUBNET))) {
+ return;
+ }
+ removeVlanAndFlood(payload, inPort);
}
}
}
@@ -126,14 +162,6 @@ public class ArpHandler {
return false;
}
- private boolean isArpReqForSubnet(DeviceId deviceId, ARP arpRequest) {
- return config.getSubnets(deviceId).stream()
- .anyMatch((prefix)->
- prefix.contains(Ip4Address.
- valueOf(arpRequest.
- getTargetProtocolAddress())));
- }
-
/**
* Sends an APR request for the target IP address to all ports except in-port.
*
@@ -170,11 +198,10 @@ public class ArpHandler {
.setSourceMACAddress(senderMacAddress)
.setEtherType(Ethernet.TYPE_ARP).setPayload(arpRequest);
- flood(eth, inPort);
+ removeVlanAndFlood(eth, inPort);
}
- private void sendArpResponse(ARP arpRequest, MacAddress targetMac) {
-
+ private void sendArpResponse(ARP arpRequest, MacAddress targetMac, VlanId vlanId) {
ARP arpReply = new ARP();
arpReply.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setProtocolType(ARP.PROTO_TYPE_IP)
@@ -193,8 +220,9 @@ public class ArpHandler {
.setEtherType(Ethernet.TYPE_ARP).setPayload(arpReply);
- HostId dstId = HostId.hostId(MacAddress.valueOf(
- arpReply.getTargetHardwareAddress()));
+ HostId dstId = HostId.hostId(
+ MacAddress.valueOf(arpReply.getTargetHardwareAddress()),
+ vlanId);
Host dst = srManager.hostService.getHost(dstId);
if (dst == null) {
log.warn("Cannot send ARP response to unknown device");
@@ -209,19 +237,51 @@ public class ArpHandler {
srManager.packetService.emit(packet);
}
- private void flood(Ethernet request, ConnectPoint inPort) {
- TrafficTreatment.Builder builder;
- ByteBuffer buf = ByteBuffer.wrap(request.serialize());
-
- for (Port port: srManager.deviceService.getPorts(inPort.deviceId())) {
- if (!port.number().equals(inPort.port()) &&
- port.number().toLong() > 0) {
- builder = DefaultTrafficTreatment.builder();
- builder.setOutput(port.number());
- srManager.packetService.emit(new DefaultOutboundPacket(inPort.deviceId(),
- builder.build(), buf));
+ /**
+ * Remove VLAN tag and flood to all ports in the same subnet.
+ *
+ * @param packet packet to be flooded
+ * @param inPort where the packet comes from
+ */
+ private void removeVlanAndFlood(Ethernet packet, ConnectPoint inPort) {
+ Ip4Address targetProtocolAddress = Ip4Address.valueOf(
+ ((ARP) packet.getPayload()).getTargetProtocolAddress()
+ );
+
+ srManager.deviceConfiguration.getSubnetPortsMap(inPort.deviceId()).forEach((subnet, ports) -> {
+ if (subnet.contains(targetProtocolAddress)) {
+ ports.stream()
+ .filter(port -> port != inPort.port())
+ .forEach(port -> {
+ removeVlanAndForward(packet, new ConnectPoint(inPort.deviceId(), port));
+ });
}
- }
+ });
}
+ /**
+ * Remove VLAN tag and packet out to given port.
+ *
+ * Note: In current implementation, we expect all communication with
+ * end hosts within a subnet to be untagged.
+ * <p>
+ * For those pipelines that internally assigns a VLAN, the VLAN tag will be
+ * removed before egress.
+ * <p>
+ * For those pipelines that do not assign internal VLAN, the packet remains
+ * untagged.
+ *
+ * @param packet packet to be forwarded
+ * @param outPort where the packet should be forwarded
+ */
+ private void removeVlanAndForward(Ethernet packet, ConnectPoint outPort) {
+ packet.setEtherType(Ethernet.TYPE_ARP);
+ packet.setVlanID(Ethernet.VLAN_UNTAGGED);
+ ByteBuffer buf = ByteBuffer.wrap(packet.serialize());
+
+ TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
+ tbuilder.setOutput(outPort.port());
+ srManager.packetService.emit(new DefaultOutboundPacket(outPort.deviceId(),
+ tbuilder.build(), buf));
+ }
}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
index c4267ebb..eb3b3fd5 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
@@ -105,8 +105,17 @@ public class IcmpHandler {
}
}
+ /**
+ * Sends an ICMP reply message.
+ *
+ * Note: we assume that packets sending from the edge switches to the hosts
+ * have untagged VLAN.
+ * @param icmpRequest the original ICMP request
+ * @param outport the output port where the ICMP reply should be sent to
+ */
private void sendICMPResponse(Ethernet icmpRequest, ConnectPoint outport) {
-
+ // Note: We assume that packets arrive at the edge switches have
+ // untagged VLAN.
Ethernet icmpReplyEth = new Ethernet();
IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
@@ -129,7 +138,6 @@ public class IcmpHandler {
icmpReplyEth.setEtherType(Ethernet.TYPE_IPV4);
icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress());
icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress());
- icmpReplyEth.setVlanID(icmpRequest.getVlanID());
Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress());
Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress);
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index f8274038..bc3ce8c6 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -55,7 +55,6 @@ import java.util.concurrent.atomic.AtomicLong;
import static com.google.common.base.Preconditions.checkNotNull;
public class RoutingRulePopulator {
-
private static final Logger log = LoggerFactory
.getLogger(RoutingRulePopulator.class);
@@ -105,13 +104,45 @@ public class RoutingRulePopulator {
*/
public void populateIpRuleForHost(DeviceId deviceId, Ip4Address hostIp,
MacAddress hostMac, PortNumber outPort) {
- MacAddress deviceMac;
+ log.debug("Populate IP table entry for host {} at {}:{}",
+ hostIp, deviceId, outPort);
+ ForwardingObjective.Builder fwdBuilder;
try {
- deviceMac = config.getDeviceMac(deviceId);
+ fwdBuilder = getForwardingObjectiveBuilder(
+ deviceId, hostIp, hostMac, outPort);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting populateIpRuleForHost.");
return;
}
+ srManager.flowObjectiveService.
+ forward(deviceId, fwdBuilder.add(new SRObjectiveContext(deviceId,
+ SRObjectiveContext.ObjectiveType.FORWARDING)));
+ rulePopulationCounter.incrementAndGet();
+ }
+
+ public void revokeIpRuleForHost(DeviceId deviceId, Ip4Address hostIp,
+ MacAddress hostMac, PortNumber outPort) {
+ log.debug("Revoke IP table entry for host {} at {}:{}",
+ hostIp, deviceId, outPort);
+ ForwardingObjective.Builder fwdBuilder;
+ try {
+ fwdBuilder = getForwardingObjectiveBuilder(
+ deviceId, hostIp, hostMac, outPort);
+ } catch (DeviceConfigNotFoundException e) {
+ log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
+ return;
+ }
+ srManager.flowObjectiveService.
+ forward(deviceId, fwdBuilder.remove(new SRObjectiveContext(deviceId,
+ SRObjectiveContext.ObjectiveType.FORWARDING)));
+ }
+
+ private ForwardingObjective.Builder getForwardingObjectiveBuilder(
+ DeviceId deviceId, Ip4Address hostIp,
+ MacAddress hostMac, PortNumber outPort)
+ throws DeviceConfigNotFoundException {
+ MacAddress deviceMac;
+ deviceMac = config.getDeviceMac(deviceId);
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
@@ -127,19 +158,10 @@ public class RoutingRulePopulator {
TrafficTreatment treatment = tbuilder.build();
TrafficSelector selector = sbuilder.build();
- ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective
- .builder().fromApp(srManager.appId).makePermanent()
+ return DefaultForwardingObjective.builder()
+ .fromApp(srManager.appId).makePermanent()
.withSelector(selector).withTreatment(treatment)
.withPriority(100).withFlag(ForwardingObjective.Flag.SPECIFIC);
-
- log.debug("Installing IPv4 forwarding objective "
- + "for host {} in switch {}", hostIp, deviceId);
- srManager.flowObjectiveService.
- forward(deviceId,
- fwdBuilder.
- add(new SRObjectiveContext(deviceId,
- SRObjectiveContext.ObjectiveType.FORWARDING)));
- rulePopulationCounter.incrementAndGet();
}
/**
@@ -186,26 +208,25 @@ public class RoutingRulePopulator {
}
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
- TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
-
sbuilder.matchIPDst(ipPrefix);
sbuilder.matchEthType(Ethernet.TYPE_IPV4);
+ TrafficSelector selector = sbuilder.build();
- NeighborSet ns = null;
+ TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
+ NeighborSet ns;
+ TrafficTreatment treatment;
// If the next hop is the same as the final destination, then MPLS label
// is not set.
if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) {
- tbuilder.deferred().decNwTtl();
+ tbuilder.immediate().decNwTtl();
ns = new NeighborSet(nextHops);
+ treatment = tbuilder.build();
} else {
- tbuilder.deferred().copyTtlOut();
ns = new NeighborSet(nextHops, segmentId);
+ treatment = null;
}
- TrafficTreatment treatment = tbuilder.build();
- TrafficSelector selector = sbuilder.build();
-
if (srManager.getNextObjectiveId(deviceId, ns) <= 0) {
log.warn("No next objective in {} for ns: {}", deviceId, ns);
return false;
@@ -216,10 +237,12 @@ public class RoutingRulePopulator {
.fromApp(srManager.appId)
.makePermanent()
.nextStep(srManager.getNextObjectiveId(deviceId, ns))
- .withTreatment(treatment)
.withSelector(selector)
.withPriority(100)
.withFlag(ForwardingObjective.Flag.SPECIFIC);
+ if (treatment != null) {
+ fwdBuilder.withTreatment(treatment);
+ }
log.debug("Installing IPv4 forwarding objective "
+ "for router IP/subnet {} in switch {}",
ipPrefix,
@@ -423,8 +446,6 @@ public class RoutingRulePopulator {
? VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET)
: srManager.getSubnetAssignedVlanId(deviceId, portSubnet);
-
-
FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
fob.withKey(Criteria.matchInPort(port.number()))
.addCondition(Criteria.matchEthDst(deviceMac))
@@ -469,14 +490,14 @@ public class RoutingRulePopulator {
Set<Ip4Address> allIps = new HashSet<Ip4Address>(config.getPortIPs(deviceId));
allIps.add(routerIp);
for (Ip4Address ipaddr : allIps) {
- TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
- TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
- selector.matchEthType(Ethernet.TYPE_IPV4);
- selector.matchIPDst(IpPrefix.valueOf(ipaddr,
+ TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
+ TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
+ sbuilder.matchEthType(Ethernet.TYPE_IPV4);
+ sbuilder.matchIPDst(IpPrefix.valueOf(ipaddr,
IpPrefix.MAX_INET_MASK_LENGTH));
- treatment.setOutput(PortNumber.CONTROLLER);
- puntIp.withSelector(selector.build());
- puntIp.withTreatment(treatment.build());
+ tbuilder.setOutput(PortNumber.CONTROLLER);
+ puntIp.withSelector(sbuilder.build());
+ puntIp.withTreatment(tbuilder.build());
puntIp.withFlag(Flag.VERSATILE)
.withPriority(HIGHEST_PRIORITY)
.makePermanent()
@@ -489,6 +510,48 @@ public class RoutingRulePopulator {
}
}
+ /**
+ * Populates a forwarding objective to send packets that miss other high
+ * priority Bridging Table entries to a group that contains all ports of
+ * its subnet.
+ *
+ * Note: We assume that packets sending from the edge switches to the hosts
+ * have untagged VLAN.
+ * The VLAN tag will be popped later in the flooding group.
+ *
+ * @param deviceId switch ID to set the rules
+ */
+ public void populateSubnetBroadcastRule(DeviceId deviceId) {
+ config.getSubnets(deviceId).forEach(subnet -> {
+ int nextId = srManager.getSubnetNextObjectiveId(deviceId, subnet);
+ VlanId vlanId = srManager.getSubnetAssignedVlanId(deviceId, subnet);
+
+ /* Driver should treat objective with MacAddress.NONE as the
+ * subnet broadcast rule
+ */
+ TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
+ sbuilder.matchVlanId(vlanId);
+ sbuilder.matchEthDst(MacAddress.NONE);
+
+ ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
+ fob.withFlag(Flag.SPECIFIC)
+ .withSelector(sbuilder.build())
+ .nextStep(nextId)
+ .withPriority(5)
+ .fromApp(srManager.appId)
+ .makePermanent();
+
+ srManager.flowObjectiveService.forward(
+ deviceId,
+ fob.add(new SRObjectiveContext(
+ deviceId,
+ SRObjectiveContext.ObjectiveType.FORWARDING)
+ )
+ );
+ });
+ }
+
+
private PortNumber selectOnePort(DeviceId srcId, Set<DeviceId> destIds) {
Set<Link> links = srManager.linkService.getDeviceLinks(srcId);
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
index 787f9347..84fe5168 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java
@@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ethernet;
+import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
@@ -33,11 +34,23 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.event.Event;
import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.PortNumber;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigRegistry;
import org.onosproject.net.config.NetworkConfigListener;
import org.onosproject.net.config.basics.SubjectFactories;
+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.flowobjective.DefaultForwardingObjective;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.onosproject.net.flowobjective.Objective;
+import org.onosproject.net.flowobjective.ObjectiveContext;
+import org.onosproject.net.flowobjective.ObjectiveError;
+import org.onosproject.net.host.HostEvent;
+import org.onosproject.net.host.HostListener;
import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
import org.onosproject.segmentrouting.config.DeviceConfiguration;
import org.onosproject.segmentrouting.config.SegmentRoutingConfig;
@@ -139,11 +152,13 @@ public class SegmentRoutingManager implements SegmentRoutingService {
private static ScheduledFuture<?> eventHandlerFuture = null;
private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<Event>();
- private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<DeviceId, DefaultGroupHandler>();
+ private Map<DeviceId, DefaultGroupHandler> groupHandlerMap =
+ new ConcurrentHashMap<DeviceId, DefaultGroupHandler>();
// Per device next objective ID store with (device id + neighbor set) as key
- private EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey,
- Integer> nsNextObjStore = null;
- private EventuallyConsistentMap<SubnetNextObjectiveStoreKey, Integer> subnetNextObjStore = null;
+ private EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, Integer>
+ nsNextObjStore = null;
+ private EventuallyConsistentMap<SubnetNextObjectiveStoreKey, Integer>
+ subnetNextObjStore = null;
private EventuallyConsistentMap<String, Tunnel> tunnelStore = null;
private EventuallyConsistentMap<String, Policy> policyStore = null;
// Per device, per-subnet assigned-vlans store, with (device id + subnet
@@ -170,6 +185,8 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
};
+ private final HostListener hostListener = new InternalHostListener();
+
private Object threadSchedulerLock = new Object();
private static int numOfEventsQueued = 0;
private static int numOfEventsExecuted = 0;
@@ -259,6 +276,8 @@ public class SegmentRoutingManager implements SegmentRoutingService {
cfgService.addListener(cfgListener);
cfgService.registerConfigFactory(cfgFactory);
+ hostService.addListener(hostListener);
+
processor = new InternalPacketProcessor();
linkListener = new InternalLinkListener();
deviceListener = new InternalDeviceListener();
@@ -637,6 +656,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
if (mastershipService.isLocalMaster(device.id())) {
DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
groupHandler.createGroupsFromSubnetConfig();
+ routingRulePopulator.populateSubnetBroadcastRule(device.id());
}
}
@@ -703,6 +723,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
if (mastershipService.isLocalMaster(device.id())) {
DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id());
groupHandler.createGroupsFromSubnetConfig();
+ routingRulePopulator.populateSubnetBroadcastRule(device.id());
}
}
@@ -723,4 +744,205 @@ public class SegmentRoutingManager implements SegmentRoutingService {
}
}
}
+
+ private class InternalHostListener implements HostListener {
+ private ForwardingObjective.Builder getForwardingObjectiveBuilder(
+ MacAddress mac, VlanId vlanId, PortNumber port) {
+ TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
+ sbuilder.matchEthDst(mac);
+ sbuilder.matchVlanId(vlanId);
+
+ TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
+ // TODO Move popVlan from flow action to group action
+ tbuilder.immediate().popVlan();
+ tbuilder.immediate().setOutput(port);
+
+ return DefaultForwardingObjective.builder()
+ .withFlag(ForwardingObjective.Flag.SPECIFIC)
+ .withSelector(sbuilder.build())
+ .withTreatment(tbuilder.build())
+ .withPriority(100)
+ .fromApp(appId)
+ .makePermanent();
+ }
+
+ private void processHostAddedEvent(HostEvent event) {
+ MacAddress mac = event.subject().mac();
+ VlanId vlanId = event.subject().vlan();
+ DeviceId deviceId = event.subject().location().deviceId();
+ PortNumber port = event.subject().location().port();
+ Set<IpAddress> ips = event.subject().ipAddresses();
+ log.debug("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port);
+
+ // TODO Move bridging table population to a separate class
+ // Populate bridging table entry
+ ForwardingObjective.Builder fob =
+ getForwardingObjectiveBuilder(mac, vlanId, port);
+ flowObjectiveService.forward(deviceId, fob.add(
+ new BridgingTableObjectiveContext(mac, vlanId)
+ ));
+
+ // Populate IP table entry
+ ips.forEach(ip -> {
+ if (ip.isIp4()) {
+ routingRulePopulator.populateIpRuleForHost(
+ deviceId, ip.getIp4Address(), mac, port);
+ }
+ });
+ }
+
+ private void processHostRemoveEvent(HostEvent event) {
+ MacAddress mac = event.subject().mac();
+ VlanId vlanId = event.subject().vlan();
+ DeviceId deviceId = event.subject().location().deviceId();
+ PortNumber port = event.subject().location().port();
+ Set<IpAddress> ips = event.subject().ipAddresses();
+ log.debug("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port);
+
+ // Revoke bridging table entry
+ ForwardingObjective.Builder fob =
+ getForwardingObjectiveBuilder(mac, vlanId, port);
+ flowObjectiveService.forward(deviceId, fob.remove(
+ new BridgingTableObjectiveContext(mac, vlanId)
+ ));
+
+ // Revoke IP table entry
+ ips.forEach(ip -> {
+ if (ip.isIp4()) {
+ routingRulePopulator.revokeIpRuleForHost(
+ deviceId, ip.getIp4Address(), mac, port);
+ }
+ });
+ }
+
+ private void processHostMovedEvent(HostEvent event) {
+ MacAddress mac = event.subject().mac();
+ VlanId vlanId = event.subject().vlan();
+ DeviceId prevDeviceId = event.prevSubject().location().deviceId();
+ PortNumber prevPort = event.prevSubject().location().port();
+ Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
+ DeviceId newDeviceId = event.subject().location().deviceId();
+ PortNumber newPort = event.subject().location().port();
+ Set<IpAddress> newIps = event.subject().ipAddresses();
+ log.debug("Host {}/{} is moved from {}:{} to {}:{}",
+ mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort);
+
+ // Revoke previous bridging table entry
+ ForwardingObjective.Builder prevFob =
+ getForwardingObjectiveBuilder(mac, vlanId, prevPort);
+ flowObjectiveService.forward(prevDeviceId, prevFob.remove(
+ new BridgingTableObjectiveContext(mac, vlanId)
+ ));
+
+ // Revoke previous IP table entry
+ prevIps.forEach(ip -> {
+ if (ip.isIp4()) {
+ routingRulePopulator.revokeIpRuleForHost(
+ prevDeviceId, ip.getIp4Address(), mac, prevPort);
+ }
+ });
+
+ // Populate new bridging table entry
+ ForwardingObjective.Builder newFob =
+ getForwardingObjectiveBuilder(mac, vlanId, prevPort);
+ flowObjectiveService.forward(newDeviceId, newFob.add(
+ new BridgingTableObjectiveContext(mac, vlanId)
+ ));
+
+ // Populate new IP table entry
+ newIps.forEach(ip -> {
+ if (ip.isIp4()) {
+ routingRulePopulator.populateIpRuleForHost(
+ newDeviceId, ip.getIp4Address(), mac, newPort);
+ }
+ });
+ }
+
+ private void processHostUpdatedEvent(HostEvent event) {
+ MacAddress mac = event.subject().mac();
+ VlanId vlanId = event.subject().vlan();
+ DeviceId prevDeviceId = event.prevSubject().location().deviceId();
+ PortNumber prevPort = event.prevSubject().location().port();
+ Set<IpAddress> prevIps = event.prevSubject().ipAddresses();
+ DeviceId newDeviceId = event.subject().location().deviceId();
+ PortNumber newPort = event.subject().location().port();
+ Set<IpAddress> newIps = event.subject().ipAddresses();
+ log.debug("Host {}/{} is updated", mac, vlanId);
+
+ // Revoke previous IP table entry
+ prevIps.forEach(ip -> {
+ if (ip.isIp4()) {
+ routingRulePopulator.revokeIpRuleForHost(
+ prevDeviceId, ip.getIp4Address(), mac, prevPort);
+ }
+ });
+
+ // Populate new IP table entry
+ newIps.forEach(ip -> {
+ if (ip.isIp4()) {
+ routingRulePopulator.populateIpRuleForHost(
+ newDeviceId, ip.getIp4Address(), mac, newPort);
+ }
+ });
+ }
+
+ @Override
+ public void event(HostEvent event) {
+ // Do not proceed without mastership
+ DeviceId deviceId = event.subject().location().deviceId();
+ if (!mastershipService.isLocalMaster(deviceId)) {
+ return;
+ }
+
+ switch (event.type()) {
+ case HOST_ADDED:
+ processHostAddedEvent(event);
+ break;
+ case HOST_MOVED:
+ processHostMovedEvent(event);
+ break;
+ case HOST_REMOVED:
+ processHostRemoveEvent(event);
+ break;
+ case HOST_UPDATED:
+ processHostUpdatedEvent(event);
+ break;
+ default:
+ log.warn("Unsupported host event type: {}", event.type());
+ break;
+ }
+ }
+ }
+
+ private static class BridgingTableObjectiveContext implements ObjectiveContext {
+ final MacAddress mac;
+ final VlanId vlanId;
+
+ BridgingTableObjectiveContext(MacAddress mac, VlanId vlanId) {
+ this.mac = mac;
+ this.vlanId = vlanId;
+ }
+
+ @Override
+ public void onSuccess(Objective objective) {
+ if (objective.op() == Objective.Operation.ADD) {
+ log.debug("Successfully populate bridging table entry for {}/{}",
+ mac, vlanId);
+ } else {
+ log.debug("Successfully revoke bridging table entry for {}/{}",
+ mac, vlanId);
+ }
+ }
+
+ @Override
+ public void onError(Objective objective, ObjectiveError error) {
+ if (objective.op() == Objective.Operation.ADD) {
+ log.debug("Fail to populate bridging table entry for {}/{}. {}",
+ mac, vlanId, error);
+ } else {
+ log.debug("Fail to revoke bridging table entry for {}/{}. {}",
+ mac, vlanId, error);
+ }
+ }
+ }
}
diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java
index 55b556eb..b394db5e 100644
--- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java
+++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java
@@ -224,8 +224,8 @@ public class DefaultGroupHandler {
.setEthSrc(nodeMacAddr);
if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
tBuilder.pushMpls()
- .setMpls(MplsLabel.
- mplsLabel(ns.getEdgeLabel()));
+ .copyTtlOut()
+ .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel()));
}
Integer nextId = nsNextObjStore.
@@ -292,8 +292,9 @@ public class DefaultGroupHandler {
.setEthDst(dstMac)
.setEthSrc(nodeMacAddr);
if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
- tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns
- .getEdgeLabel()));
+ tBuilder.pushMpls()
+ .copyTtlOut()
+ .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel()));
}
Integer nextId = nsNextObjStore.
@@ -536,8 +537,9 @@ public class DefaultGroupHandler {
.setEthDst(deviceMac)
.setEthSrc(nodeMacAddr);
if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
- tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns
- .getEdgeLabel()));
+ tBuilder.pushMpls()
+ .copyTtlOut()
+ .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel()));
}
nextObjBuilder.addTreatment(tBuilder.build());
}
diff --git a/framework/src/onos/apps/vtn/pom.xml b/framework/src/onos/apps/vtn/pom.xml
index e8387cb7..a42f91a0 100644
--- a/framework/src/onos/apps/vtn/pom.xml
+++ b/framework/src/onos/apps/vtn/pom.xml
@@ -32,13 +32,14 @@
<description>ONOS framework applications</description>
<modules>
+ <module>sfcmgr</module>
<module>vtnrsc</module>
<module>vtnmgr</module>
<module>vtnweb</module>
<module>app</module>
- </modules>
- <dependencies>
- <dependency>
+ </modules>
+ <dependencies>
+ <dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-junit</artifactId>
<scope>test</scope>
@@ -53,5 +54,25 @@
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey.jersey-test-framework</groupId>
+ <artifactId>jersey-test-framework-grizzly2</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java
deleted file mode 100644
index a2748f5e..00000000
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java
+++ /dev/null
@@ -1,52 +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.sfc;
-
-import org.onosproject.vtnrsc.PortChain;
-
-/**
- * SFC application that applies flows to the device.
- */
-public interface SfcService {
- /**
- * Applies flow classification to OVS.
- *
- * @param portChain Port-Chain.
- */
- void InstallFlowClassification(PortChain portChain);
-
-
- /**
- * Remove flow classification from OVS.
- *
- * @param portChain Port-Chain.
- */
- void UnInstallFlowClassification(PortChain portChain);
-
- /**
- * Applies Service Function chain to OVS.
- *
- * @param portChain Port-Chain.
- */
- void InstallServiceFunctionChain(PortChain portChain);
-
- /**
- * Remove Service Function chain from OVS.
- *
- * @param portChain Port-Chain.
- */
- void UnInstallServiceFunctionChain(PortChain portChain);
-}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java
deleted file mode 100644
index 1872295f..00000000
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java
+++ /dev/null
@@ -1,69 +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.sfc.impl;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-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.Service;
-import org.onosproject.vtnrsc.sfc.PortChain;
-import org.slf4j.Logger;
-
-/**
- * Provides implementation of SFC Service.
- */
-@Component(immediate = true)
-@Service
-public class SfcManager implements SfcService {
-
- private final Logger log = getLogger(SfcManager.class);
-
- @Activate
- public void activate() {
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- log.info("Stopped");
- }
-
- @Override
- public void InstallFlowClassification(PortChain portChain) {
- log.debug("InstallFlowClassification");
- //TODO: Installation of flow classification into OVS.
- }
-
- @Override
- public void UnInstallFlowClassification(PortChain portChain) {
- log.debug("UnInstallFlowClassification");
- //TODO: Un-installation flow classification from OVS
- }
-
- @Override
- public void InstallServiceFunctionChain(PortChain portChain) {
- log.debug("InstallServiceFunctionChain");
- //TODO: Installation of Service Function chain into OVS.
- }
-
- @Override
- public void UnInstallServiceFunctionChain(PortChain portChain) {
- log.debug("UnInstallServiceFunctionChain");
- //TODO: Un-installation of Service Function chain from OVS.
- }
-}
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java
deleted file mode 100644
index 0dba868c..00000000
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/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.
- */
-
-/**
- * SFC Service manager for interacting with SFC.
- */
-package org.onosproject.sfc.impl;
diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java
deleted file mode 100644
index 1dcb9929..00000000
--- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/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.
- */
-
-/**
- * Service for interacting with SFC.
- */
-package org.onosproject.sfc;
diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java
deleted file mode 100644
index a20f852b..00000000
--- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java
+++ /dev/null
@@ -1,68 +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.vtn;
-
-import org.onosproject.net.Device;
-import org.onosproject.net.Host;
-
-/**
- * VTN application that applies configuration and flows to the device.
- */
-public interface VTNService {
-
- /**
- * Creates a vxlan tunnel and creates the ovs when a ovs controller node is detected.
- *
- * @param device controller-type device
- */
- void onServerDetected(Device device);
-
- /**
- * Drops a vxlan tunnel and drops the ovs when a ovs controller node is vanished.
- *
- * @param device controller-type device
- */
- void onServerVanished(Device device);
-
- /**
- * Applies default forwarding flows when a ovs is detected.
- *
- * @param device switch-type device
- */
- void onOvsDetected(Device device);
-
- /**
- * Remove default forwarding flows when a ovs is vanished.
- *
- * @param device switch-type device
- */
- void onOvsVanished(Device device);
-
- /**
- * Applies multicast flows and tunnel flows when a VM is detected.
- *
- * @param host a VM
- */
- void onHostDetected(Host host);
-
- /**
- * Remove multicast flows and tunnel flows when a VM is vanished.
- *
- * @param host a VM
- */
- void onHostVanished(Host host);
-
-}
diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java
deleted file mode 100644
index 090ef0f1..00000000
--- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java
+++ /dev/null
@@ -1,672 +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.vtn.impl;
-
-import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
-import static org.onlab.util.Tools.groupedThreads;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.stream.Collectors;
-
-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.osgi.DefaultServiceDirectory;
-import org.onlab.osgi.ServiceDirectory;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.MacAddress;
-import org.onlab.util.KryoNamespace;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-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.PortNumber;
-import org.onosproject.net.behaviour.BridgeConfig;
-import org.onosproject.net.behaviour.BridgeDescription;
-import org.onosproject.net.behaviour.BridgeName;
-import org.onosproject.net.behaviour.DefaultTunnelDescription;
-import org.onosproject.net.behaviour.IpTunnelEndPoint;
-import org.onosproject.net.behaviour.Pipeliner;
-import org.onosproject.net.behaviour.PipelinerContext;
-import org.onosproject.net.behaviour.TunnelConfig;
-import org.onosproject.net.behaviour.TunnelDescription;
-import org.onosproject.net.behaviour.TunnelEndPoint;
-import org.onosproject.net.device.DeviceEvent;
-import org.onosproject.net.device.DeviceListener;
-import org.onosproject.net.device.DeviceService;
-import org.onosproject.net.driver.DefaultDriverData;
-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.FlowRuleService;
-import org.onosproject.net.flow.TrafficSelector;
-import org.onosproject.net.flow.TrafficTreatment;
-import org.onosproject.net.flow.criteria.Criteria;
-import org.onosproject.net.flow.instructions.Instructions;
-import org.onosproject.net.flowobjective.DefaultForwardingObjective;
-import org.onosproject.net.flowobjective.FlowObjectiveService;
-import org.onosproject.net.flowobjective.FlowObjectiveStore;
-import org.onosproject.net.flowobjective.ForwardingObjective;
-import org.onosproject.net.flowobjective.ForwardingObjective.Flag;
-import org.onosproject.net.flowobjective.Objective;
-import org.onosproject.net.host.HostEvent;
-import org.onosproject.net.host.HostListener;
-import org.onosproject.net.host.HostService;
-import org.onosproject.store.serializers.KryoNamespaces;
-import org.onosproject.store.service.EventuallyConsistentMap;
-import org.onosproject.store.service.StorageService;
-import org.onosproject.store.service.WallClockTimestamp;
-import org.onosproject.vtn.VTNService;
-import org.onosproject.vtnrsc.SegmentationId;
-import org.onosproject.vtnrsc.TenantNetwork;
-import org.onosproject.vtnrsc.VirtualPort;
-import org.onosproject.vtnrsc.VirtualPortId;
-import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
-import org.onosproject.vtnrsc.virtualport.VirtualPortService;
-import org.slf4j.Logger;
-
-import com.google.common.collect.Sets;
-
-/**
- * Provides implementation of VTNService.
- */
-@Component(immediate = true)
-@Service
-public class VTNManager implements VTNService {
- private final Logger log = getLogger(getClass());
-
- private static final String APP_ID = "org.onosproject.app.vtn";
- private ScheduledExecutorService backgroundService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostService hostService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowRuleService flowRuleService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected StorageService storageService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected TenantNetworkService tenantNetworkService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected VirtualPortService virtualPortService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DriverService driverService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowObjectiveService flowObjectiveService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowObjectiveStore flowObjectiveStore;
- protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
- private EventuallyConsistentMap<HostId, SegmentationId> binding;
- private ApplicationId appId;
- private HostListener hostListener = new InnerHostListener();
- private DeviceListener deviceListener = new InnerDeviceListener();
- private static final String IFACEID = "ifaceid";
- private static final String PORT_HEAD = "vxlan";
- private static final String DEFAULT_BRIDGE_NAME = "br-int";
- private static final String CONTROLLER_IP_KEY = "ipaddress";
- private static final int DEFAULT_MAC_PRIORITY = 0x0000;
- private static final int MAC_PRIORITY = 0xffff;
- private static final int DEFAULT_PORT_PRIORITY = 0x0000;
- private static final int PORT_PRIORITY = 0xffff;
- private static final String SWITCH_CHANNEL_ID = "channelId";
- private static final String DRIVER_NAME = "onosfw";
-
- @Activate
- public void activate() {
- KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
- .register(KryoNamespaces.API);
- appId = coreService.registerApplication(APP_ID);
- deviceService.addListener(deviceListener);
- hostService.addListener(hostListener);
- backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos-apps/vtn",
- "manager-background"));
- binding = storageService
- .<HostId, SegmentationId>eventuallyConsistentMapBuilder()
- .withName("all_tunnel").withSerializer(serializer)
- .withTimestampProvider((k, v) -> new WallClockTimestamp())
- .build();
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- backgroundService.shutdown();
- binding.destroy();
- log.info("Stopped");
- }
-
- @Override
- public void onServerDetected(Device device) {
- Iterable<Device> devices = deviceService.getAvailableDevices();
- DriverHandler handler = driverService.createHandler(device.id());
- BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
- bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME));
- String ipAddress = device.annotations().value(CONTROLLER_IP_KEY);
- IpAddress ip = IpAddress.valueOf(ipAddress);
- Sets.newHashSet(devices).stream()
- .filter(d -> Device.Type.CONTROLLER == d.type())
- .filter(d -> !device.id().equals(d.id())).forEach(d -> {
- String ipAddress1 = d.annotations()
- .value(CONTROLLER_IP_KEY);
- IpAddress ip1 = IpAddress.valueOf(ipAddress1);
- applyTunnelConfig(ip, ip1, handler);
- DriverHandler handler1 = driverService
- .createHandler(d.id());
- applyTunnelConfig(ip1, ip, handler1);
-
- });
- }
-
- @Override
- public void onServerVanished(Device device) {
- Iterable<Device> devices = deviceService.getAvailableDevices();
- String ipAddress = device.annotations().value(CONTROLLER_IP_KEY);
- IpAddress dst = IpAddress.valueOf(ipAddress);
- Sets.newHashSet(devices).stream()
- .filter(d -> d.type() == Device.Type.CONTROLLER)
- .filter(d -> !device.id().equals(d.id())).forEach(d -> {
- String ipAddress1 = d.annotations()
- .value(CONTROLLER_IP_KEY);
- DriverHandler handler = driverService.createHandler(d.id());
- IpAddress src = IpAddress.valueOf(ipAddress1);
- removeTunnelConfig(src, dst, handler);
- });
- }
-
- private void applyTunnelConfig(IpAddress src, IpAddress dst,
- DriverHandler handler) {
- TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src);
- TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst);
- TunnelDescription tunnel = new DefaultTunnelDescription(
- tunnelAsSrc,
- tunnelAsDst,
- TunnelDescription.Type.VXLAN,
- null);
- TunnelConfig config = handler.behaviour(TunnelConfig.class);
- config.createTunnel(tunnel);
- }
-
- private void removeTunnelConfig(IpAddress src, IpAddress dst,
- DriverHandler handler) {
- TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src);
- TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst);
- TunnelDescription tunnel = new DefaultTunnelDescription(
- tunnelAsSrc,
- tunnelAsDst,
- TunnelDescription.Type.VXLAN,
- null);
- TunnelConfig config = handler.behaviour(TunnelConfig.class);
- config.removeTunnel(tunnel);
- }
-
- @Override
- public void onOvsDetected(Device device) {
- programMacDefaultRules(device.id(), appId, Objective.Operation.ADD);
- programPortDefaultRules(device.id(), appId, Objective.Operation.ADD);
- }
-
- @Override
- public void onOvsVanished(Device device) {
- programMacDefaultRules(device.id(), appId, Objective.Operation.REMOVE);
- programPortDefaultRules(device.id(), appId, Objective.Operation.REMOVE);
- }
-
- @Override
- public void onHostDetected(Host host) {
- String ifaceId = host.annotations().value(IFACEID);
- DeviceId deviceId = host.location().deviceId();
- String currentControllerIp = getControllerIpOfSwitch(deviceId);
- Iterable<Device> devices = deviceService.getAvailableDevices();
- VirtualPortId portId = VirtualPortId.portId(ifaceId);
- VirtualPort port = virtualPortService.getPort(portId);
- TenantNetwork network = tenantNetworkService
- .getNetwork(port.networkId());
- String tunnelName = "vxlan-" + currentControllerIp;
- binding.put(host.id(), network.segmentationId());
- List<Port> allPorts = deviceService.getPorts(deviceId);
- PortNumber inPort = host.location().port();
- List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId);
- List<PortNumber> localTunnelPorts = new ArrayList<>();
- Sets.newHashSet(allPorts.iterator()).stream()
- .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> {
- if (p.annotations().value("portName").startsWith(PORT_HEAD)) {
- localTunnelPorts.add(p.number());
- }
- });
-
- localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, network.segmentationId(), lp, localVmPorts,
- localTunnelPorts, appId, Objective.Operation.ADD));
- programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(),
- appId, Objective.Operation.ADD);
- localTunnelPorts
- .forEach(tp -> programTunnelFloodOut(deviceId,
- network.segmentationId(),
- tp, localVmPorts,
- appId,
- Objective.Operation.ADD));
- Sets.newHashSet(devices).stream()
- .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> {
- DriverHandler handler = driverService.createHandler(d.id());
- BridgeConfig bridgeConfig = handler
- .behaviour(BridgeConfig.class);
- Collection<BridgeDescription> bridgeDescriptions = bridgeConfig
- .getBridges();
-
- Iterator<BridgeDescription> it = bridgeDescriptions
- .iterator();
- if (it.hasNext()) {
- BridgeDescription sw = it.next();
- Set<PortNumber> ports = bridgeConfig.getPortNumbers();
- ports.stream()
- .filter(p -> p.name()
- .equalsIgnoreCase(tunnelName))
- .forEach(p -> programTunnelOut(sw.deviceId(),
- network.segmentationId(), p,
- host.mac(), appId,
- Objective.Operation.ADD));
- }
- });
- programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(),
- appId, Objective.Operation.ADD);
- localTunnelPorts
- .forEach(tp -> programTunnelIn(deviceId,
- network.segmentationId(),
- tp, inPort, host.mac(),
- appId, Objective.Operation.ADD));
-
- }
-
- @Override
- public void onHostVanished(Host host) {
- String ifaceId = host.annotations().value(IFACEID);
- SegmentationId segId = binding.remove(host.id());
- DeviceId deviceId = host.location().deviceId();
- String currentControllerIp = getControllerIpOfSwitch(deviceId);
- Iterable<Device> devices = deviceService.getAvailableDevices();
-
- String tunnelName = "vxlan-" + currentControllerIp;
- List<Port> allPorts = deviceService.getPorts(deviceId);
- PortNumber inPort = host.location().port();
-
- List<PortNumber> localTunnelPorts = new ArrayList<>();
- Sets.newHashSet(allPorts.iterator()).stream()
- .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> {
- if (p.annotations().value("portName").startsWith(PORT_HEAD)) {
- localTunnelPorts.add(p.number());
- }
- });
-
- List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId);
- localVmPorts.add(inPort);
- localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, segId, lp, localVmPorts,
- localTunnelPorts, appId, Objective.Operation.REMOVE));
- programLocalOut(deviceId, segId, inPort, host.mac(),
- appId, Objective.Operation.REMOVE);
- localTunnelPorts
- .forEach(tp -> programTunnelFloodOut(deviceId,
- segId,
- tp, localVmPorts,
- appId,
- Objective.Operation.REMOVE));
- Sets.newHashSet(devices).stream()
- .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> {
- DriverHandler handler = driverService.createHandler(d.id());
- BridgeConfig bridgeConfig = handler
- .behaviour(BridgeConfig.class);
- Collection<BridgeDescription> bridgeDescriptions = bridgeConfig
- .getBridges();
-
- Iterator<BridgeDescription> it = bridgeDescriptions
- .iterator();
- if (it.hasNext()) {
- BridgeDescription sw = it.next();
- Set<PortNumber> ports = bridgeConfig.getPortNumbers();
- ports.stream()
- .filter(p -> p.name()
- .equalsIgnoreCase(tunnelName))
- .forEach(p -> programTunnelOut(sw.deviceId(),
- segId, p,
- host.mac(), appId,
- Objective.Operation.REMOVE));
- }
- });
- programLocalIn(deviceId, segId, inPort, host.mac(),
- appId, Objective.Operation.REMOVE);
- localTunnelPorts
- .forEach(tp -> programTunnelIn(deviceId,
- segId,
- tp, inPort, host.mac(),
- appId, Objective.Operation.REMOVE));
- }
-
- private class InnerDeviceListener implements DeviceListener {
-
- @Override
- public void event(DeviceEvent event) {
- Device device = event.subject();
- if (Device.Type.CONTROLLER == device.type()
- && DeviceEvent.Type.DEVICE_ADDED == event.type()) {
- backgroundService.execute(() -> onServerDetected(device));
- } else if (Device.Type.CONTROLLER == device.type()
- && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event
- .type()) {
- backgroundService.execute(() -> onServerVanished(device));
- } else if (Device.Type.SWITCH == device.type()
- && DeviceEvent.Type.DEVICE_ADDED == event.type()) {
- backgroundService.execute(() -> onOvsDetected(device));
- } else if (Device.Type.SWITCH == device.type()
- && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event
- .type()) {
- backgroundService.execute(() -> onOvsVanished(device));
- } else {
- log.info("Do nothing for this device type");
- }
- }
-
- }
-
- private class InnerHostListener implements HostListener {
-
- @Override
- public void event(HostEvent event) {
- Host host = event.subject();
- if (HostEvent.Type.HOST_ADDED == event.type()) {
- backgroundService.execute(() -> onHostDetected(host));
- } else if (HostEvent.Type.HOST_REMOVED == event.type()) {
- backgroundService.execute(() -> onHostVanished(host));
- } else if (HostEvent.Type.HOST_UPDATED == event.type()) {
- backgroundService.execute(() -> {
- onHostVanished(host);
- onHostDetected(host);
- });
- }
- }
-
- }
-
- // Used to forward the flows to the local VM.
- private void programLocalOut(DeviceId dpid, SegmentationId segmentationId,
- PortNumber outPort, MacAddress sourceMac,
- ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchTunnelId(Long.parseLong(segmentationId.toString()))
- .matchEthDst(sourceMac).build();
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
- .setOutput(outPort).build();
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment).withSelector(selector)
- .fromApp(appId).withFlag(Flag.SPECIFIC)
- .withPriority(MAC_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(dpid, objective.add());
- } else {
- flowServiceForward(dpid, objective.remove());
- }
-
- }
-
- // Used to forward the flows into the VXLAN tunnel.
- private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId,
- PortNumber tunnelOutPort, MacAddress dstMac,
- ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long
- .parseLong(segmentationId.toString())))
- .build();
- TrafficTreatment treatment = DefaultTrafficTreatment.builder()
-
- .setOutput(tunnelOutPort).build();
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment).withSelector(selector)
- .fromApp(appId).withFlag(Flag.SPECIFIC)
- .withPriority(MAC_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(dpid, objective.add());
- } else {
- flowServiceForward(dpid, objective.remove());
- }
-
- }
-
- // Used to forward multicast flows to remote VMs of the same tenant via
- // VXLAN tunnel.
- private void programTunnelFloodOut(DeviceId deviceId,
- SegmentationId segmentationId,
- PortNumber ofPortOut,
- List<PortNumber> localVmPorts,
- ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchInPort(ofPortOut)
-
- .add(Criteria.matchTunnelId(Long.parseLong(segmentationId
- .toString()))).matchEthDst(MacAddress.BROADCAST)
- .build();
- TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
-
- for (PortNumber outPort : localVmPorts) {
- treatment.setOutput(outPort);
- }
-
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment.build())
- .withSelector(selector).fromApp(appId).makePermanent()
- .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(deviceId, objective.add());
- } else {
- flowServiceForward(deviceId, objective.remove());
- }
- }
-
- // Applies default flows to mac table.
- private void programMacDefaultRules(DeviceId dpid, ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder().build();
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop()
- .build();
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment).withSelector(selector)
- .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC)
- .withPriority(DEFAULT_MAC_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(dpid, objective.add());
- } else {
- flowServiceForward(dpid, objective.remove());
- }
- }
-
- // Used to forward the flows to the local VMs with the same tenant.
- private void programLocalBcastRules(DeviceId deviceId,
- SegmentationId segmentationId,
- PortNumber inPort,
- List<PortNumber> localVmPorts,
- List<PortNumber> localTunnelPorts,
- ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST)
- .add(Criteria.matchTunnelId(Long
- .parseLong(segmentationId.toString())))
- .build();
- TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
- for (PortNumber outPort : localVmPorts) {
- if (inPort != outPort) {
- treatment.setOutput(outPort);
- }
- }
- for (PortNumber outport : localTunnelPorts) {
- treatment.setOutput(outport);
- }
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment.build())
- .withSelector(selector).fromApp(appId).makePermanent()
- .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(deviceId, objective.add());
- } else {
- flowServiceForward(deviceId, objective.remove());
- }
- }
-
- // Used to apply local entry flow.
- private void programLocalIn(DeviceId dpid, SegmentationId segmentationId,
- PortNumber inPort, MacAddress srcMac,
- ApplicationId appid, Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchInPort(inPort).matchEthSrc(srcMac).build();
- TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
- treatment.add(Instructions.modTunnelId(Long.parseLong(segmentationId
- .toString())));
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment.build())
- .withSelector(selector).fromApp(appId).makePermanent()
- .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(dpid, objective.add());
- } else {
- flowServiceForward(dpid, objective.remove());
- }
- }
-
- // Used to forward the flows from the egress tunnel to the VM.
- private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId,
- PortNumber tunnelInPort, PortNumber outPort,
- MacAddress sourceMac, ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder()
- .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long
- .parseLong(segmentationId.toString())))
- .build();
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
-
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment).withSelector(selector)
- .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC)
- .withPriority(PORT_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(dpid, objective.add());
- } else {
- flowServiceForward(dpid, objective.remove());
- }
- }
-
- // Applies the default flows to port table.
- private void programPortDefaultRules(DeviceId dpid, ApplicationId appid,
- Objective.Operation type) {
- TrafficSelector selector = DefaultTrafficSelector.builder().build();
- TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
- ForwardingObjective.Builder objective = DefaultForwardingObjective
- .builder().withTreatment(treatment).withSelector(selector)
- .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC)
- .withPriority(DEFAULT_PORT_PRIORITY);
- if (type.equals(Objective.Operation.ADD)) {
- flowServiceForward(dpid, objective.add());
- } else {
- flowServiceForward(dpid, objective.remove());
- }
- }
-
- // Used to get channelId from the device annotations.
- private String getControllerIpOfSwitch(DeviceId deviceId) {
- Device device = deviceService.getDevice(deviceId);
- String url = device.annotations().value(SWITCH_CHANNEL_ID);
- return url.substring(0, url.lastIndexOf(":"));
- }
-
- private Iterable<String> getIfaceIds(String ifaceId) {
- VirtualPortId portId = VirtualPortId.portId(ifaceId);
- VirtualPort port = virtualPortService.getPort(portId);
- if (port == null) {
- return Collections.emptyList();
- }
-
- TenantNetwork network = tenantNetworkService
- .getNetwork(port.networkId());
- if (network == null) {
- return Collections.emptyList();
- }
-
- Collection<VirtualPort> ports = virtualPortService
- .getPorts(network.id());
- return ports.stream().map(p -> p.portId().portId())
- .collect(Collectors.toSet());
- }
-
- private List<PortNumber> getLocalPorts(DeviceId deviceId, String ifaceId) {
- DriverHandler handler = driverService
- .createHandler(getController(deviceId));
- BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class);
- Iterable<String> ifaceIds = getIfaceIds(ifaceId);
- return bridgeConfig.getLocalPorts(ifaceIds);
- }
-
- private DeviceId getController(DeviceId deviceId) {
- Iterable<Device> devices = deviceService.getAvailableDevices();
- for (Device device : devices) {
- if (device.type() == Device.Type.CONTROLLER && device.id()
- .toString().contains(getControllerIpOfSwitch(deviceId))) {
- return device.id();
- }
- }
- log.info("Can not find controller for device : {}", deviceId);
- return null;
- }
-
- //Used to apply flowRule
- private void flowServiceForward(DeviceId deviceId, ForwardingObjective forwardingObjective) {
- Driver driver = driverService.getDriver(DRIVER_NAME);
- Pipeliner pipeLiner = driver.createBehaviour(new DefaultDriverData(driver, deviceId), Pipeliner.class);
- if (pipeLiner != null) {
- final PipelinerContext context = new InnerPipelineContext();
- pipeLiner.init(deviceId, context);
- pipeLiner.forward(forwardingObjective);
- }
- }
-
- // Processing context for initializing pipeline driver behaviours.
- private class InnerPipelineContext implements PipelinerContext {
- @Override
- public ServiceDirectory directory() {
- return serviceDirectory;
- }
-
- @Override
- public FlowObjectiveStore store() {
- return flowObjectiveStore;
- }
- }
-
-}
diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java
deleted file mode 100644
index f18dbf8a..00000000
--- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/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.
- */
-
-/**
- * VTN application that applies configuration and flows to the device.
- */
-package org.onosproject.vtn.impl;
diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java
deleted file mode 100644
index 371466c3..00000000
--- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/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.
- */
-
-/**
- * VTN application that applies configuration and flows to the device.
- */
-package org.onosproject.vtn;
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
index 39df2cff..7915ce08 100644
--- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
+++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java
@@ -43,6 +43,8 @@ public final class DefaultFlowClassifier implements FlowClassifier {
private static final int NULL_PORT = 0;
private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "FlowClassifier id can not be null.";
private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null.";
+ private static final String NAME_NOT_NULL = "Name can not be null.";
+ private static final String ETHER_TYPE_NOT_NULL = "Ether Type can not be null.";
/**
* Constructor to create default flow classifier.
@@ -160,11 +162,9 @@ public final class DefaultFlowClassifier implements FlowClassifier {
private FlowClassifierId flowClassifierId;
private TenantId tenantId;
private String name;
- private boolean isFlowClassifierNameSet = false;
private String description;
private boolean isFlowClassifierDescriptionSet = false;
private String etherType;
- private boolean isEtherTypeSet = false;
private String protocol;
private boolean isProtocolSet = false;
private int minSrcPortRange;
@@ -189,9 +189,9 @@ public final class DefaultFlowClassifier implements FlowClassifier {
checkNotNull(flowClassifierId, FLOW_CLASSIFIER_ID_NOT_NULL);
checkNotNull(tenantId, TENANT_ID_NOT_NULL);
- String name = null;
+ checkNotNull(name, NAME_NOT_NULL);
+ checkNotNull(etherType, ETHER_TYPE_NOT_NULL);
String description = null;
- String etherType = null;
String protocol = null;
int minSrcPortRange = NULL_PORT;
int maxSrcPortRange = NULL_PORT;
@@ -202,15 +202,9 @@ public final class DefaultFlowClassifier implements FlowClassifier {
VirtualPortId srcPort = null;
VirtualPortId dstPort = null;
- if (isFlowClassifierNameSet) {
- name = this.name;
- }
if (isFlowClassifierDescriptionSet) {
description = this.description;
}
- if (isEtherTypeSet) {
- etherType = this.etherType;
- }
if (isProtocolSet) {
protocol = this.protocol;
}
@@ -259,7 +253,6 @@ public final class DefaultFlowClassifier implements FlowClassifier {
@Override
public Builder setName(String name) {
this.name = name;
- this.isFlowClassifierNameSet = true;
return this;
}
@@ -273,7 +266,6 @@ public final class DefaultFlowClassifier implements FlowClassifier {
@Override
public Builder setEtherType(String etherType) {
this.etherType = etherType;
- this.isEtherTypeSet = true;
return this;
}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java
deleted file mode 100644
index 6b0d9a64..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/DefaultFlowClassifierTest.java
+++ /dev/null
@@ -1,148 +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.vtnrsc.flowclassifier;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onlab.packet.IpPrefix;
-import org.onosproject.vtnrsc.TenantId;
-import org.onosproject.vtnrsc.DefaultFlowClassifier;
-import org.onosproject.vtnrsc.FlowClassifierId;
-import org.onosproject.vtnrsc.VirtualPortId;
-import org.onosproject.vtnrsc.FlowClassifier;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultFlowClassifier class.
- */
-public class DefaultFlowClassifierTest {
- /**
- * Checks that the DefaultFlowClassifier class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultFlowClassifier.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- // Create same two flow classifier objects.
- final String name = "FlowClassifier1";
- final String description = "FlowClassifier1";
- final String ethType = "IPv4";
- final String protocol = "tcp";
- final int minSrcPortRange = 5;
- final int maxSrcPortRange = 10;
- final int minDstPortRange = 5;
- final int maxDstPortRange = 10;
- final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
- final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0");
- final VirtualPortId virtualSrcPort = VirtualPortId.portId("1");
- final VirtualPortId virtualDstPort = VirtualPortId.portId("2");
-
- DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
- final FlowClassifier flowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
- .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
- .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
- .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
- .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
-
- flowClassifierBuilder = new DefaultFlowClassifier.Builder();
- final FlowClassifier sameAsFlowClassifier1 = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
- .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
- .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
- .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
- .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
-
- // Create different classifier object.
- final String name2 = "FlowClassifier2";
- final String description2 = "FlowClassifier2";
- final String ethType2 = "IPv6";
- final String protocol2 = "udp";
- final int minSrcPortRange2 = 5;
- final int maxSrcPortRange2 = 10;
- final int minDstPortRange2 = 5;
- final int maxDstPortRange2 = 10;
- final FlowClassifierId flowClassifierId2 = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId2 = TenantId.tenantId("2");
- final IpPrefix srcIpPrefix2 = IpPrefix.valueOf("0.0.0.0/0");
- final IpPrefix dstIpPrefix2 = IpPrefix.valueOf("10.10.10.10/0");
- final VirtualPortId virtualSrcPort2 = VirtualPortId.portId("3");
- final VirtualPortId virtualDstPort2 = VirtualPortId.portId("4");
-
- DefaultFlowClassifier.Builder flowClassifierBuilder3 = new DefaultFlowClassifier.Builder();
- final FlowClassifier flowClassifier2 = flowClassifierBuilder3.setFlowClassifierId(flowClassifierId2)
- .setTenantId(tenantId2).setName(name2).setDescription(description2).setEtherType(ethType2)
- .setProtocol(protocol2).setMinSrcPortRange(minSrcPortRange2).setMaxSrcPortRange(maxSrcPortRange2)
- .setMinDstPortRange(minDstPortRange2).setMaxDstPortRange(maxDstPortRange2).setSrcIpPrefix(srcIpPrefix2)
- .setDstIpPrefix(dstIpPrefix2).setSrcPort(virtualSrcPort2).setDstPort(virtualDstPort2).build();
-
- new EqualsTester().addEqualityGroup(flowClassifier1, sameAsFlowClassifier1).addEqualityGroup(flowClassifier2)
- .testEquals();
- }
-
- /**
- * Checks the construction of a DefaultFlowClassifier object.
- */
- @Test
- public void testConstruction() {
- final String name = "FlowClassifier";
- final String description = "FlowClassifier";
- final String ethType = "IPv4";
- final String protocol = "tcp";
- final int minSrcPortRange = 5;
- final int maxSrcPortRange = 10;
- final int minDstPortRange = 5;
- final int maxDstPortRange = 10;
- final FlowClassifierId flowClassifierId = FlowClassifierId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final IpPrefix srcIpPrefix = IpPrefix.valueOf("0.0.0.0/0");
- final IpPrefix dstIpPrefix = IpPrefix.valueOf("10.10.10.10/0");
- final VirtualPortId virtualSrcPort = VirtualPortId.portId("1");
- final VirtualPortId virtualDstPort = VirtualPortId.portId("2");
-
- DefaultFlowClassifier.Builder flowClassifierBuilder = new DefaultFlowClassifier.Builder();
- final FlowClassifier flowClassifier = flowClassifierBuilder.setFlowClassifierId(flowClassifierId)
- .setTenantId(tenantId).setName(name).setDescription(description).setEtherType(ethType)
- .setProtocol(protocol).setMinSrcPortRange(minSrcPortRange).setMaxSrcPortRange(maxSrcPortRange)
- .setMinDstPortRange(minDstPortRange).setMaxDstPortRange(maxDstPortRange).setSrcIpPrefix(srcIpPrefix)
- .setDstIpPrefix(dstIpPrefix).setSrcPort(virtualSrcPort).setDstPort(virtualDstPort).build();
-
- assertThat(flowClassifierId, is(flowClassifier.flowClassifierId()));
- assertThat(tenantId, is(flowClassifier.tenantId()));
- assertThat(name, is(flowClassifier.name()));
- assertThat(description, is(flowClassifier.description()));
- assertThat(ethType, is(flowClassifier.etherType()));
- assertThat(protocol, is(flowClassifier.protocol()));
- assertThat(minSrcPortRange, is(flowClassifier.minSrcPortRange()));
- assertThat(maxSrcPortRange, is(flowClassifier.maxSrcPortRange()));
- assertThat(minDstPortRange, is(flowClassifier.minDstPortRange()));
- assertThat(maxDstPortRange, is(flowClassifier.maxDstPortRange()));
- assertThat(srcIpPrefix, is(flowClassifier.srcIpPrefix()));
- assertThat(dstIpPrefix, is(flowClassifier.dstIpPrefix()));
- assertThat(virtualSrcPort, is(flowClassifier.srcPort()));
- assertThat(virtualDstPort, is(flowClassifier.dstPort()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java
deleted file mode 100644
index 4f521836..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java
+++ /dev/null
@@ -1,68 +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.vtnrsc.flowclassifier;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.FlowClassifierId;
-
-import com.google.common.testing.EqualsTester;
-import java.util.UUID;
-
-/**
- * Unit tests for FlowClassifierId class.
- */
-public class FlowClassifierIdTest {
-
- final FlowClassifierId flowClassifierId1 = FlowClassifierId
- .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId
- .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final FlowClassifierId flowClassifierId2 = FlowClassifierId
- .of("dace4513-24fc-4fae-af4b-321c5e2eb3d1");
-
- /**
- * Checks that the FlowClassifierId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(FlowClassifierId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(flowClassifierId1, sameAsFlowClassifierId1)
- .addEqualityGroup(flowClassifierId2).testEquals();
- }
-
- /**
- * Checks the construction of a FlowClassifierId object.
- */
- @Test
- public void testConstruction() {
- final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1";
- final FlowClassifierId flowClassifierId = FlowClassifierId.of(flowClassifierIdValue);
- assertThat(flowClassifierId, is(notNullValue()));
- assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue)));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java
deleted file mode 100644
index b9ce73d8..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/DefaultPortChainTest.java
+++ /dev/null
@@ -1,140 +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.vtnrsc.flowclassifier;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import java.util.List;
-import java.util.LinkedList;
-
-import org.onosproject.vtnrsc.PortChainId;
-import org.onosproject.vtnrsc.PortPairGroupId;
-import org.onosproject.vtnrsc.TenantId;
-import org.onosproject.vtnrsc.FlowClassifierId;
-import org.onosproject.vtnrsc.PortChain;
-import org.onosproject.vtnrsc.DefaultPortChain;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultPortChain class.
- */
-public class DefaultPortChainTest {
- /**
- * Checks that the DefaultPortChain class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultPortChain.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- // Create same two port chain objects.
- final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortChain1";
- final String description = "PortChain1";
- // create list of Port Pair Groups.
- final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
- PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairGroups.add(portPairGroupId);
- portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
- portPairGroups.add(portPairGroupId);
- // create list of Flow classifiers.
- final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
- FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- flowClassifiers.add(flowClassifierId);
- flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
- flowClassifiers.add(flowClassifierId);
-
- DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
- final PortChain portChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
- .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
- .build();
-
- portChainBuilder = new DefaultPortChain.Builder();
- final PortChain samePortChain1 = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
- .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
- .build();
-
- // Create different port chain object.
- final PortChainId portChainId2 = PortChainId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId2 = TenantId.tenantId("2");
- final String name2 = "PortChain2";
- final String description2 = "PortChain2";
- // create list of Port Pair Groups.
- final List<PortPairGroupId> portPairGroups2 = new LinkedList<PortPairGroupId>();
- portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairGroups2.add(portPairGroupId);
- portPairGroupId = PortPairGroupId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3af");
- portPairGroups2.add(portPairGroupId);
- // create list of Flow classifiers.
- final List<FlowClassifierId> flowClassifiers2 = new LinkedList<FlowClassifierId>();
- flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3ae");
- flowClassifiers2.add(flowClassifierId);
- flowClassifierId = FlowClassifierId.of("76666666-fc23-aeb6-f44b-56dc5e2fb3af");
- flowClassifiers2.add(flowClassifierId);
-
- portChainBuilder = new DefaultPortChain.Builder();
- final PortChain portChain2 = portChainBuilder.setId(portChainId2).setTenantId(tenantId2).setName(name2)
- .setDescription(description2).setPortPairGroups(portPairGroups2).setFlowClassifiers(flowClassifiers2)
- .build();
-
- new EqualsTester().addEqualityGroup(portChain1, samePortChain1).addEqualityGroup(portChain2).testEquals();
- }
-
- /**
- * Checks the construction of a DefaultPortChain object.
- */
- @Test
- public void testConstruction() {
- final PortChainId portChainId = PortChainId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortChain";
- final String description = "PortChain";
- // create list of Port Pair Groups.
- final List<PortPairGroupId> portPairGroups = new LinkedList<PortPairGroupId>();
- PortPairGroupId portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairGroups.add(portPairGroupId);
- portPairGroupId = PortPairGroupId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3af");
- portPairGroups.add(portPairGroupId);
- // create list of Flow classifiers.
- final List<FlowClassifierId> flowClassifiers = new LinkedList<FlowClassifierId>();
- FlowClassifierId flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- flowClassifiers.add(flowClassifierId);
- flowClassifierId = FlowClassifierId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3af");
- flowClassifiers.add(flowClassifierId);
-
- DefaultPortChain.Builder portChainBuilder = new DefaultPortChain.Builder();
- final PortChain portChain = portChainBuilder.setId(portChainId).setTenantId(tenantId).setName(name)
- .setDescription(description).setPortPairGroups(portPairGroups).setFlowClassifiers(flowClassifiers)
- .build();
-
- assertThat(portChainId, is(portChain.portChainId()));
- assertThat(tenantId, is(portChain.tenantId()));
- assertThat(name, is(portChain.name()));
- assertThat(description, is(portChain.description()));
- assertThat(portPairGroups, is(portChain.portPairGroups()));
- assertThat(flowClassifiers, is(portChain.flowClassifiers()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java
deleted file mode 100644
index a87bdb99..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portchain/PortChainIdTest.java
+++ /dev/null
@@ -1,65 +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.vtnrsc.portchain;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.PortChainId;
-
-import com.google.common.testing.EqualsTester;
-import java.util.UUID;
-
-/**
- * Unit tests for PortChainId class.
- */
-public class PortChainIdTest {
-
- final PortChainId portChainId1 = PortChainId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final PortChainId sameAsPortChainId1 = PortChainId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final PortChainId portChainId2 = PortChainId.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1");
-
- /**
- * Checks that the PortChainId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(PortChainId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(portChainId1, sameAsPortChainId1).addEqualityGroup(portChainId2)
- .testEquals();
- }
-
- /**
- * Checks the construction of a PortChainId object.
- */
- @Test
- public void testConstruction() {
- final String portChainIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1";
- final PortChainId portChainId = PortChainId.of(portChainIdValue);
- assertThat(portChainId, is(notNullValue()));
- assertThat(portChainId.value(), is(UUID.fromString(portChainIdValue)));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java
deleted file mode 100644
index 91e7ab37..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/DefaultPortPairTest.java
+++ /dev/null
@@ -1,102 +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.vtnrsc.flowclassifier;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-
-import org.onosproject.vtnrsc.PortPairId;
-import org.onosproject.vtnrsc.TenantId;
-import org.onosproject.vtnrsc.PortPair;
-import org.onosproject.vtnrsc.DefaultPortPair;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultPortPair class.
- */
-public class DefaultPortPairTest {
- /**
- * Checks that the DefaultPortPair class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultPortPair.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- // Create same two port pair objects.
- final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortPair1";
- final String description = "PortPair1";
- final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
- final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
-
- DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
- final PortPair portPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
- .setDescription(description).setIngress(ingress).setEgress(egress).build();
-
- portPairBuilder = new DefaultPortPair.Builder();
- final PortPair samePortPair1 = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
- .setDescription(description).setIngress(ingress).setEgress(egress).build();
-
- // Create different port pair object.
- final PortPairId portPairId2 = PortPairId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId2 = TenantId.tenantId("2");
- final String name2 = "PortPair2";
- final String description2 = "PortPair2";
- final String ingress2 = "d5555555-24fc-4fae-af4b-321c5e2eb3d1";
- final String egress2 = "a6666666-4a56-2a6e-cd3a-9dee4e2ec345";
-
- portPairBuilder = new DefaultPortPair.Builder();
- final PortPair portPair2 = portPairBuilder.setId(portPairId2).setTenantId(tenantId2).setName(name2)
- .setDescription(description2).setIngress(ingress2).setEgress(egress2).build();
-
- new EqualsTester().addEqualityGroup(portPair1, samePortPair1).addEqualityGroup(portPair2).testEquals();
- }
-
- /**
- * Checks the construction of a DefaultPortPair object.
- */
- @Test
- public void testConstruction() {
- final PortPairId portPairId = PortPairId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortPair";
- final String description = "PortPair";
- final String ingress = "d3333333-24fc-4fae-af4b-321c5e2eb3d1";
- final String egress = "a4444444-4a56-2a6e-cd3a-9dee4e2ec345";
-
- DefaultPortPair.Builder portPairBuilder = new DefaultPortPair.Builder();
- final PortPair portPair = portPairBuilder.setId(portPairId).setTenantId(tenantId).setName(name)
- .setDescription(description).setIngress(ingress).setEgress(egress).build();
-
- assertThat(portPairId, is(portPair.portPairId()));
- assertThat(tenantId, is(portPair.tenantId()));
- assertThat(name, is(portPair.name()));
- assertThat(description, is(portPair.description()));
- assertThat(ingress, is(portPair.ingress()));
- assertThat(egress, is(portPair.egress()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.java
deleted file mode 100644
index f176089e..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpair/PortPairIdTest.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.vtnrsc.portpair;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.PortPairId;
-
-import com.google.common.testing.EqualsTester;
-import java.util.UUID;
-
-/**
- * Unit tests for PortPairId class.
- */
-public class PortPairIdTest {
-
- final PortPairId portPairId1 = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final PortPairId sameAsPortPairId1 = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final PortPairId portPairId2 = PortPairId.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1");
-
- /**
- * Checks that the PortPairId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(PortPairId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(portPairId1, sameAsPortPairId1).addEqualityGroup(portPairId2).testEquals();
- }
-
- /**
- * Checks the construction of a PortPairId object.
- */
- @Test
- public void testConstruction() {
- final String portPairIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1";
- final PortPairId portPairId = PortPairId.of(portPairIdValue);
- assertThat(portPairId, is(notNullValue()));
- assertThat(portPairId.value(), is(UUID.fromString(portPairIdValue)));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java
deleted file mode 100644
index 2528fb29..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/DefaultPortPairGroupTest.java
+++ /dev/null
@@ -1,117 +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.vtnrsc.flowclassifier;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import java.util.List;
-import java.util.LinkedList;
-
-import org.onosproject.vtnrsc.PortPairGroupId;
-import org.onosproject.vtnrsc.PortPairId;
-import org.onosproject.vtnrsc.TenantId;
-import org.onosproject.vtnrsc.PortPairGroup;
-import org.onosproject.vtnrsc.DefaultPortPairGroup;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultPortPairGroup class.
- */
-public class DefaultPortPairGroupTest {
- /**
- * Checks that the DefaultPortPairGroup class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultPortPairGroup.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- // Create same two port-pair-group objects.
- final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortPairGroup1";
- final String description = "PortPairGroup1";
- // create port-pair-id list
- final List<PortPairId> portPairList = new LinkedList<PortPairId>();
- PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
- portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
-
- DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup portPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
- .setName(name).setDescription(description).setPortPairs(portPairList).build();
-
- portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup samePortPairGroup1 = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
- .setName(name).setDescription(description).setPortPairs(portPairList).build();
-
- // Create different port-pair-group object.
- final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("79999999-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId2 = TenantId.tenantId("2");
- final String name2 = "PortPairGroup2";
- final String description2 = "PortPairGroup2";
- // create port-pair-id list
- final List<PortPairId> portPairList2 = new LinkedList<PortPairId>();
- portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList2.add(portPairId);
- portPairId = PortPairId.of("75555555-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList2.add(portPairId);
-
- portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup portPairGroup2 = portPairGroupBuilder.setId(portPairGroupId2).setTenantId(tenantId2)
- .setName(name2).setDescription(description2).setPortPairs(portPairList2).build();
-
- new EqualsTester().addEqualityGroup(portPairGroup1, samePortPairGroup1).addEqualityGroup(portPairGroup2)
- .testEquals();
- }
-
- /**
- * Checks the construction of a DefaultPortPairGroup object.
- */
- @Test
- public void testConstruction() {
- final PortPairGroupId portPairGroupId = PortPairGroupId.of("78888888-fc23-aeb6-f44b-56dc5e2fb3ae");
- final TenantId tenantId = TenantId.tenantId("1");
- final String name = "PortPairGroup";
- final String description = "PortPairGroup";
- // create port-pair-id list
- final List<PortPairId> portPairList = new LinkedList<PortPairId>();
- PortPairId portPairId = PortPairId.of("73333333-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
- portPairId = PortPairId.of("74444444-fc23-aeb6-f44b-56dc5e2fb3ae");
- portPairList.add(portPairId);
-
- DefaultPortPairGroup.Builder portPairGroupBuilder = new DefaultPortPairGroup.Builder();
- final PortPairGroup portPairGroup = portPairGroupBuilder.setId(portPairGroupId).setTenantId(tenantId)
- .setName(name).setDescription(description).setPortPairs(portPairList).build();
-
- assertThat(portPairGroupId, is(portPairGroup.portPairGroupId()));
- assertThat(tenantId, is(portPairGroup.tenantId()));
- assertThat(name, is(portPairGroup.name()));
- assertThat(description, is(portPairGroup.description()));
- assertThat(portPairList, is(portPairGroup.portPairs()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java
deleted file mode 100644
index 25db9d2e..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupIdTest.java
+++ /dev/null
@@ -1,66 +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.vtnrsc.portpairgroup;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.PortPairGroupId;
-
-import com.google.common.testing.EqualsTester;
-import java.util.UUID;
-
-/**
- * Unit tests for PortPairGroupId class.
- */
-public class PortPairGroupIdTest {
-
- final PortPairGroupId portPairGroupId1 = PortPairGroupId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final PortPairGroupId sameAsPortPairGroupId1 = PortPairGroupId
- .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae");
- final PortPairGroupId portPairGroupId2 = PortPairGroupId.of("dace4513-24fc-4fae-af4b-321c5e2eb3d1");
-
- /**
- * Checks that the PortPairGroupId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(PortPairGroupId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(portPairGroupId1, sameAsPortPairGroupId1)
- .addEqualityGroup(portPairGroupId2).testEquals();
- }
-
- /**
- * Checks the construction of a PortPairGroupId object.
- */
- @Test
- public void testConstruction() {
- final String portPairGroupIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1";
- final PortPairGroupId portPairGroupId = PortPairGroupId.of(portPairGroupIdValue);
- assertThat(portPairGroupId, is(notNullValue()));
- assertThat(portPairGroupId.value(), is(UUID.fromString(portPairGroupIdValue)));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java
deleted file mode 100644
index ce6b6c00..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterGatewayTest.java
+++ /dev/null
@@ -1,82 +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.vtnrsc.router;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.RouterGateway;
-import org.onosproject.vtnrsc.TenantNetworkId;
-import org.onosproject.vtnrsc.FixedIp;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for RouterGateway class.
- */
-public class RouterGatewayTest {
- final TenantNetworkId networkId1 = TenantNetworkId.networkId("1");
- final TenantNetworkId networkId2 = TenantNetworkId.networkId("2");
- final Set<FixedIp> fixedIpSet1 = new HashSet<>();
- final Set<FixedIp> fixedIpSet2 = new HashSet<>();
-
- /**
- * Checks that the RouterGateway class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(RouterGateway.class);
- }
-
- /**
- * Checks the operation of equals().
- */
- @Test
- public void testEquals() {
- RouterGateway routerGateway1 = RouterGateway.routerGateway(networkId1,
- true,
- fixedIpSet1);
- RouterGateway routerGateway2 = RouterGateway.routerGateway(networkId1,
- true,
- fixedIpSet1);
- RouterGateway routerGateway3 = RouterGateway.routerGateway(networkId2,
- true,
- fixedIpSet2);
- new EqualsTester().addEqualityGroup(routerGateway1, routerGateway2)
- .addEqualityGroup(routerGateway3).testEquals();
- }
-
- /**
- * Checks the construction of a RouterGateway object.
- */
- @Test
- public void testConstruction() {
- RouterGateway routerGateway = RouterGateway.routerGateway(networkId1,
- true,
- fixedIpSet1);
- assertThat(fixedIpSet1, is(notNullValue()));
- assertThat(fixedIpSet1, is(routerGateway.externalFixedIps()));
- assertThat(networkId1, is(notNullValue()));
- assertThat(networkId1, is(routerGateway.networkId()));
- assertThat(routerGateway.enableSnat(), is(true));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java
deleted file mode 100644
index 3751c11a..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/router/RouterIdTest.java
+++ /dev/null
@@ -1,63 +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.vtnrsc.router;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.RouterId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for RouterId class.
- */
-public class RouterIdTest {
- final RouterId routerId1 = RouterId.valueOf("1");
- final RouterId sameAsRouterId1 = RouterId.valueOf("1");
- final RouterId routerId2 = RouterId.valueOf("2");
-
- /**
- * Checks that the RouterId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(RouterId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(routerId1, sameAsRouterId1).addEqualityGroup(routerId2)
- .testEquals();
- }
-
- /**
- * Checks the construction of a RouterId object.
- */
- @Test
- public void testConstruction() {
- final String routerIdValue = "s";
- final RouterId routerId = RouterId.valueOf(routerIdValue);
- assertThat(routerId, is(notNullValue()));
- assertThat(routerId.routerId(), is(routerIdValue));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java
deleted file mode 100644
index 4ce4def2..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java
+++ /dev/null
@@ -1,68 +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.vtnrsc.subnet;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onlab.packet.IpAddress;
-import org.onosproject.vtnrsc.AllocationPool;
-import org.onosproject.vtnrsc.DefaultAllocationPool;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultAllocationPool class.
- */
-public class DefaultAllocationPoolTest {
-
- final IpAddress startIP1 = IpAddress.valueOf("192.168.1.1");
- final IpAddress startIP2 = IpAddress.valueOf("192.168.1.2");
- final IpAddress endIP1 = IpAddress.valueOf("192.168.1.1");
- final IpAddress endIP2 = IpAddress.valueOf("192.168.1.2");
-
- /**
- * Checks that the DefaultAllocationPool class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultAllocationPool.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- AllocationPool pool1 = new DefaultAllocationPool(startIP1, endIP1);
- AllocationPool pool2 = new DefaultAllocationPool(startIP1, endIP1);
- AllocationPool pool3 = new DefaultAllocationPool(startIP2, endIP2);
- new EqualsTester().addEqualityGroup(pool1, pool2)
- .addEqualityGroup(pool3).testEquals();
- }
-
- /**
- * Checks the construction of a DefaultAllocationPool object.
- */
- @Test
- public void testConstruction() {
- final AllocationPool apool = new DefaultAllocationPool(startIP1, endIP1);
- assertThat(startIP1, is(apool.startIp()));
- assertThat(endIP1, is(apool.endIp()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java
deleted file mode 100644
index 2f751742..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java
+++ /dev/null
@@ -1,68 +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.vtnrsc.subnet;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.IpPrefix;
-import org.onosproject.vtnrsc.DefaultHostRoute;
-import org.onosproject.vtnrsc.HostRoute;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultHostRoute class.
- */
-public class DefaultHostRouteTest {
- final IpAddress nexthop1 = IpAddress.valueOf("192.168.1.1");
- final IpAddress nexthop2 = IpAddress.valueOf("192.168.1.2");
- final IpPrefix destination1 = IpPrefix.valueOf("1.1.1.1/1");
- final IpPrefix destination2 = IpPrefix.valueOf("1.1.1.1/2");
-
- /**
- * Checks that the DefaultHostRoute class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultHostRoute.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- HostRoute route1 = new DefaultHostRoute(nexthop1, destination1);
- HostRoute route2 = new DefaultHostRoute(nexthop1, destination1);
- HostRoute route3 = new DefaultHostRoute(nexthop2, destination2);
- new EqualsTester().addEqualityGroup(route1, route2)
- .addEqualityGroup(route3).testEquals();
- }
-
- /**
- * Checks the construction of a DefaultHostRoute object.
- */
- @Test
- public void testConstruction() {
- final HostRoute host = new DefaultHostRoute(nexthop1, destination1);
- assertThat(nexthop1, is(host.nexthop()));
- assertThat(destination1, is(host.destination()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java
deleted file mode 100644
index d18dd41a..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.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.vtnrsc.subnet;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.SubnetId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for SubnetId class.
- */
-public class SubnetIdTest {
-
- final SubnetId subnetId1 = SubnetId.subnetId("1");
- final SubnetId sameAsSubnetId1 = SubnetId.subnetId("1");
- final SubnetId subnetId2 = SubnetId.subnetId("2");
-
- /**
- * Checks that the SubnetId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(SubnetId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(subnetId1, sameAsSubnetId1).addEqualityGroup(subnetId2)
- .testEquals();
- }
-
- /**
- * Checks the construction of a SubnetId object.
- */
- @Test
- public void testConstruction() {
- final String subnetIdValue = "s";
- final SubnetId subnetId = SubnetId.subnetId(subnetIdValue);
- assertThat(subnetId, is(notNullValue()));
- assertThat(subnetId.subnetId(), is(subnetIdValue));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java
deleted file mode 100644
index 742d5933..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java
+++ /dev/null
@@ -1,83 +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.vtnrsc.tenantnetwork;
-
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.DefaultTenantNetwork;
-import org.onosproject.vtnrsc.PhysicalNetwork;
-import org.onosproject.vtnrsc.SegmentationId;
-import org.onosproject.vtnrsc.TenantId;
-import org.onosproject.vtnrsc.TenantNetwork;
-import org.onosproject.vtnrsc.TenantNetworkId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultNeutronNetwork class.
- */
-public class DefaultNeutronNetworkTest {
-
- private String networkIdStr1 = "123";
- private String networkIdStr2 = "234";
- private String physicalNetworkStr = "1234";
- private String tenantIdStr = "345";
- private String segmentationIdStr = "1";
- private String name = "456";
-
- /**
- * Checks that the DefaultNeutronNetwork class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(DefaultTenantNetwork.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquality() {
- TenantNetworkId networkid1 = TenantNetworkId.networkId(networkIdStr1);
- TenantNetworkId networkid2 = TenantNetworkId.networkId(networkIdStr2);
- PhysicalNetwork physicalNetwork = PhysicalNetwork
- .physicalNetwork(physicalNetworkStr);
- TenantId tenantId = TenantId.tenantId(tenantIdStr);
- SegmentationId segmentationID = SegmentationId
- .segmentationId(segmentationIdStr);
- TenantNetwork p1 = new DefaultTenantNetwork(networkid1, name, false,
- TenantNetwork.State.ACTIVE,
- false, tenantId, false,
- TenantNetwork.Type.LOCAL,
- physicalNetwork,
- segmentationID);
- TenantNetwork p2 = new DefaultTenantNetwork(networkid1, name, false,
- TenantNetwork.State.ACTIVE,
- false, tenantId, false,
- TenantNetwork.Type.LOCAL,
- physicalNetwork,
- segmentationID);
- TenantNetwork p3 = new DefaultTenantNetwork(networkid2, name, false,
- TenantNetwork.State.ACTIVE,
- false, tenantId, false,
- TenantNetwork.Type.LOCAL,
- physicalNetwork,
- segmentationID);
- new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3)
- .testEquals();
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java
deleted file mode 100644
index e101795e..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java
+++ /dev/null
@@ -1,65 +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.vtnrsc.tenantnetwork;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.PhysicalNetwork;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for PhysicalNetwork class.
- */
-public class PhysicalNetworkTest {
-
- final PhysicalNetwork physicalNetwork1 = PhysicalNetwork.physicalNetwork("1");
- final PhysicalNetwork sameAsPhysicalNetwork1 = PhysicalNetwork.physicalNetwork("1");
- final PhysicalNetwork physicalNetwork2 = PhysicalNetwork.physicalNetwork("2");
-
- /**
- * Checks that the PhysicalNetwork class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(PhysicalNetwork.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(physicalNetwork1, sameAsPhysicalNetwork1)
- .addEqualityGroup(physicalNetwork2).testEquals();
- }
-
- /**
- * Checks the construction of a PhysicalNetwork object.
- */
- @Test
- public void testConstruction() {
- final String physicalNetworkValue = "s";
- final PhysicalNetwork physicalNetwork = PhysicalNetwork
- .physicalNetwork(physicalNetworkValue);
- assertThat(physicalNetwork, is(notNullValue()));
- assertThat(physicalNetwork.physicalNetwork(), is(physicalNetworkValue));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java
deleted file mode 100644
index dea7baf6..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.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.vtnrsc.tenantnetwork;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.SegmentationId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for SegmentationId class.
- */
-public class SegmentationIdTest {
-
- final SegmentationId segmentationID1 = SegmentationId.segmentationId("1");
- final SegmentationId sameAsSegmentationID1 = SegmentationId.segmentationId("1");
- final SegmentationId segmentationID2 = SegmentationId.segmentationId("2");
-
- /**
- * Checks that the SegmentationId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(SegmentationId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(segmentationID1, sameAsSegmentationID1)
- .addEqualityGroup(segmentationID2).testEquals();
- }
-
- /**
- * Checks the construction of a segmentationId object.
- */
- @Test
- public void testConstruction() {
- final String segmentationIdValue = "s";
- final SegmentationId segmentationId = SegmentationId.segmentationId(segmentationIdValue);
- assertThat(segmentationId, is(notNullValue()));
- assertThat(segmentationId.segmentationId(), is(segmentationIdValue));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java
deleted file mode 100644
index e9216383..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.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.vtnrsc.tenantnetwork;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.TenantId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for TenantId class.
- */
-public class TenantIdTest {
-
- final TenantId tenantId1 = TenantId.tenantId("1");
- final TenantId sameAsTenantId1 = TenantId.tenantId("1");
- final TenantId tenantId2 = TenantId.tenantId("2");
-
- /**
- * Checks that the TenantId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(TenantId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(tenantId1, sameAsTenantId1).addEqualityGroup(tenantId2)
- .testEquals();
- }
-
- /**
- * Checks the construction of a TenantId object.
- */
- @Test
- public void testConstruction() {
- final String tenantIdValue = "s";
- final TenantId tenantId = TenantId.tenantId(tenantIdValue);
- assertThat(tenantId, is(notNullValue()));
- assertThat(tenantId.tenantId(), is(tenantIdValue));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java
deleted file mode 100644
index 8271b51c..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.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.vtnrsc.tenantnetwork;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.TenantNetworkId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for TenantNetworkId class.
- */
-public class TenantNetworkIdTest {
-
- final TenantNetworkId networkId1 = TenantNetworkId.networkId("1");
- final TenantNetworkId sameAsnetworkId1 = TenantNetworkId.networkId("1");
- final TenantNetworkId networkId2 = TenantNetworkId.networkId("2");
-
- /**
- * Checks that the TenantNetworkId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(TenantNetworkId.class);
- }
-
- /**
- * Checks the operation of equals() methods.
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(networkId1, sameAsnetworkId1)
- .addEqualityGroup(networkId2).testEquals();
- }
-
- /**
- * Checks the construction of a TenantNetworkId object.
- */
- @Test
- public void testConstruction() {
- final String networkIdValue = "s";
- final TenantNetworkId networkId = TenantNetworkId.networkId(networkIdValue);
- assertThat(networkId, is(notNullValue()));
- assertThat(networkId.networkId(), is(networkIdValue));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java
deleted file mode 100644
index dabe5896..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java
+++ /dev/null
@@ -1,76 +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.vtnrsc.virtualport;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.MacAddress;
-import org.onosproject.vtnrsc.AllowedAddressPair;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for AllowedAddressPair class.
- */
-public class AllowedAddressPairTest {
-
- final IpAddress ip1 = IpAddress.valueOf("192.168.0.1");
- final IpAddress ip2 = IpAddress.valueOf("192.168.0.2");
- final MacAddress mac1 = MacAddress.valueOf("fa:16:3e:76:83:88");
- final MacAddress mac2 = MacAddress.valueOf("aa:16:3e:76:83:88");
-
- /**
- * Checks that the AllowedAddressPair class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(AllowedAddressPair.class);
- }
-
- /**
- * Checks the operation of equals().
- */
- @Test
- public void testEquals() {
- AllowedAddressPair p1 = AllowedAddressPair
- .allowedAddressPair(ip1, mac1);
- AllowedAddressPair p2 = AllowedAddressPair
- .allowedAddressPair(ip1, mac1);
- AllowedAddressPair p3 = AllowedAddressPair
- .allowedAddressPair(ip2, mac2);
- new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3)
- .testEquals();
- }
-
- /**
- * Checks the construction of a AllowedAddressPair object.
- */
- @Test
- public void testConstruction() {
- AllowedAddressPair allowedAddressPair = AllowedAddressPair
- .allowedAddressPair(ip1, mac1);
- assertThat(ip1, is(notNullValue()));
- assertThat(ip1, is(allowedAddressPair.ip()));
- assertThat(mac1, is(notNullValue()));
- assertThat(mac1, is(allowedAddressPair.mac()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java
deleted file mode 100644
index 8a0c8004..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java
+++ /dev/null
@@ -1,142 +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.vtnrsc.virtualport;
-
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.junit.Test;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.MacAddress;
-import org.onosproject.net.DeviceId;
-import org.onosproject.vtnrsc.AllowedAddressPair;
-import org.onosproject.vtnrsc.BindingHostId;
-import org.onosproject.vtnrsc.DefaultVirtualPort;
-import org.onosproject.vtnrsc.FixedIp;
-import org.onosproject.vtnrsc.SecurityGroup;
-import org.onosproject.vtnrsc.SubnetId;
-import org.onosproject.vtnrsc.TenantId;
-import org.onosproject.vtnrsc.TenantNetworkId;
-import org.onosproject.vtnrsc.VirtualPort;
-import org.onosproject.vtnrsc.VirtualPortId;
-
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for DefaultVirtualPort class.
- */
-public class DefaultVirtualPortTest {
-
- private Set<FixedIp> fixedIps;
- private Map<String, String> propertyMap;
- private Set<AllowedAddressPair> allowedAddressPairs;
- private Set<SecurityGroup> securityGroups;
- private VirtualPortId id1;
- private VirtualPortId id2;
- private String macAddressStr = "fa:12:3e:56:ee:a2";
- private String ipAddress = "10.1.1.1";
- private String deviceStr = "of:000000000000001";
- private String tenantIdStr = "123";
- private String portId1 = "1241";
- private String portId2 = "1242";
- private String tenantNetworkId = "1234567";
- private String subnet = "1212";
- private String hostIdStr = "fa:e2:3e:56:ee:a2";
-
- private void initVirtualPortId() {
- id1 = VirtualPortId.portId(portId1);
- id2 = VirtualPortId.portId(portId2);
- }
-
- private void initFixedIpSet() {
- FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet),
- IpAddress.valueOf(ipAddress));
- fixedIps = Sets.newHashSet();
- fixedIps.add(fixedIp);
- }
-
- private void initPropertyMap() {
- String deviceOwner = "james";
- propertyMap = Maps.newHashMap();
- propertyMap.putIfAbsent("deviceOwner", deviceOwner);
- }
-
- private void initAddressPairSet() {
- allowedAddressPairs = Sets.newHashSet();
- AllowedAddressPair allowedAddressPair = AllowedAddressPair
- .allowedAddressPair(IpAddress.valueOf(ipAddress),
- MacAddress.valueOf(macAddressStr));
- allowedAddressPairs.add(allowedAddressPair);
- }
-
- private void initSecurityGroupSet() {
- securityGroups = Sets.newHashSet();
- }
-
- /**
- * Checks that the DefaultVirtualPort class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(SecurityGroup.class);
- }
-
- /**
- * Checks the operation of equals().
- */
- @Test
- public void testEquals() {
- initVirtualPortId();
- initFixedIpSet();
- initPropertyMap();
- initAddressPairSet();
- initSecurityGroupSet();
- TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId);
- MacAddress macAddress = MacAddress.valueOf(macAddressStr);
- TenantId tenantId = TenantId.tenantId(tenantIdStr);
- DeviceId deviceId = DeviceId.deviceId(deviceStr);
- BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr);
-
- VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true,
- propertyMap,
- VirtualPort.State.ACTIVE,
- macAddress, tenantId, deviceId,
- fixedIps, bindingHostId,
- allowedAddressPairs,
- securityGroups);
- VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true,
- propertyMap,
- VirtualPort.State.ACTIVE,
- macAddress, tenantId, deviceId,
- fixedIps, bindingHostId,
- allowedAddressPairs,
- securityGroups);
- VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true,
- propertyMap,
- VirtualPort.State.ACTIVE,
- macAddress, tenantId, deviceId,
- fixedIps, bindingHostId,
- allowedAddressPairs,
- securityGroups);
- new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3)
- .testEquals();
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java
deleted file mode 100644
index 1e33da09..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java
+++ /dev/null
@@ -1,72 +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.vtnrsc.virtualport;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onlab.packet.IpAddress;
-import org.onosproject.vtnrsc.FixedIp;
-import org.onosproject.vtnrsc.SubnetId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for FixedIp class.
- */
-public class FixedIpTest {
-
- final SubnetId subnetId1 = SubnetId.subnetId("lef11-95w-4er-9c9c");
- final SubnetId subnetId2 = SubnetId.subnetId("lefaa-95w-4er-9c9c");
- final IpAddress ip1 = IpAddress.valueOf("192.168.0.1");
- final IpAddress ip2 = IpAddress.valueOf("192.168.1.1");
-
- /**
- * Checks that the FixedIp class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(FixedIp.class);
- }
-
- /**
- * Checks the operation of equals().
- */
- @Test
- public void testEquals() {
- FixedIp fixedIp1 = FixedIp.fixedIp(subnetId1, ip1);
- FixedIp fixedIp2 = FixedIp.fixedIp(subnetId1, ip1);
- FixedIp fixedIp3 = FixedIp.fixedIp(subnetId2, ip2);
- new EqualsTester().addEqualityGroup(fixedIp1, fixedIp2)
- .addEqualityGroup(fixedIp3).testEquals();
- }
-
- /**
- * Checks the construction of a FixedIp object.
- */
- @Test
- public void testConstruction() {
- FixedIp fixedIp = FixedIp.fixedIp(subnetId1, ip1);
- assertThat(ip1, is(notNullValue()));
- assertThat(ip1, is(fixedIp.ip()));
- assertThat(subnetId1, is(notNullValue()));
- assertThat(subnetId1, is(fixedIp.subnetId()));
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java
deleted file mode 100644
index 8c04e499..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java
+++ /dev/null
@@ -1,66 +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.vtnrsc.virtualport;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.SecurityGroup;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for SecurityGroup class.
- */
-public class SecurityGroupTest {
-
- final SecurityGroup securityGroup1 = SecurityGroup.securityGroup("1");
- final SecurityGroup sameAssecurityGroup = SecurityGroup.securityGroup("1");
- final SecurityGroup securityGroup2 = SecurityGroup.securityGroup("2");
-
- /**
- * Checks that the SecurityGroup class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(SecurityGroup.class);
- }
-
- /**
- * Checks the operation of equals().
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(securityGroup1, sameAssecurityGroup)
- .addEqualityGroup(securityGroup2).testEquals();
- }
-
- /**
- * Checks the construction of a SecurityGroup object.
- */
- @Test
- public void testConstruction() {
- final String securityGroupValue = "1";
- final SecurityGroup securityGroup = SecurityGroup.securityGroup(securityGroupValue);
- assertThat(securityGroup, is(notNullValue()));
- assertThat(securityGroup.securityGroup(), is(securityGroupValue));
-
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java
deleted file mode 100644
index 2d63e91c..00000000
--- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java
+++ /dev/null
@@ -1,66 +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.vtnrsc.virtualport;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.notNullValue;
-import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
-import org.junit.Test;
-import org.onosproject.vtnrsc.VirtualPortId;
-
-import com.google.common.testing.EqualsTester;
-
-/**
- * Unit tests for VirtualPortId class.
- */
-public class VirtualPortIdTest {
-
- final VirtualPortId virtualPortId1 = VirtualPortId.portId("1");
- final VirtualPortId sameAsVirtualPortId1 = VirtualPortId.portId("1");
- final VirtualPortId virtualPortId2 = VirtualPortId.portId("2");
-
- /**
- * Checks that the VirtualPortId class is immutable.
- */
- @Test
- public void testImmutability() {
- assertThatClassIsImmutable(VirtualPortId.class);
- }
-
- /**
- * Checks the operation of equals().
- */
- @Test
- public void testEquals() {
- new EqualsTester().addEqualityGroup(virtualPortId1, sameAsVirtualPortId1)
- .addEqualityGroup(virtualPortId2).testEquals();
- }
-
- /**
- * Checks the construction of a VirtualPortId object.
- */
- @Test
- public void testConstruction() {
- final String vPortIdValue = "aaa";
- final VirtualPortId virtualPortId = VirtualPortId.portId(vPortIdValue);
- assertThat(virtualPortId, is(notNullValue()));
- assertThat(virtualPortId.portId(), is(vPortIdValue));
-
- }
-}
diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
index 7a57c0ab..b0e2f38d 100644
--- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
+++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java
@@ -15,15 +15,12 @@
*/
package org.onosproject.vtnweb.resources;
-import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
-import static org.onlab.util.Tools.nullIsNotFound;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static javax.ws.rs.core.Response.Status.OK;
+import static org.onlab.util.Tools.nullIsNotFound;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.UUID;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -36,13 +33,17 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.onosproject.rest.AbstractWebResource;
import org.onosproject.vtnrsc.FlowClassifier;
import org.onosproject.vtnrsc.FlowClassifierId;
-import org.onosproject.rest.AbstractWebResource;
import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
import org.onosproject.vtnweb.web.FlowClassifierCodec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
@@ -51,73 +52,51 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
@Path("flow_classifiers")
public class FlowClassifierWebResource extends AbstractWebResource {
+ private final Logger log = LoggerFactory.getLogger(FlowClassifierWebResource.class);
+
final FlowClassifierService service = get(FlowClassifierService.class);
- final ObjectNode root = mapper().createObjectNode();
public static final String FLOW_CLASSIFIER_NOT_FOUND = "Flow classifier not found";
/**
- * Get all flow classifiers created. Returns list of all flow classifiers
- * created.
+ * Get all flow classifiers created.
*
* @return 200 OK
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getFlowClassifiers() {
- Iterable<FlowClassifier> flowClassifiers = service.getFlowClassifiers();
+ final Iterable<FlowClassifier> flowClassifiers = service.getFlowClassifiers();
ObjectNode result = new ObjectMapper().createObjectNode();
- result.set("flow_classifiers", new FlowClassifierCodec().encode(flowClassifiers, this));
+ ArrayNode flowClassifierEntry = result.putArray("flow_classifiers");
+ if (flowClassifiers != null) {
+ for (final FlowClassifier flowClassifier : flowClassifiers) {
+ flowClassifierEntry.add(new FlowClassifierCodec().encode(flowClassifier, this));
+ }
+ }
return ok(result.toString()).build();
}
/**
- * Get details of a flow classifier. Returns details of a specified flow
- * classifier id.
+ * Get details of a flow classifier.
*
* @param id flow classifier id
- * @return 200 OK
+ * @return 200 OK , 404 if given identifier does not exist
*/
@GET
@Path("{flow_id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getFlowClassifier(@PathParam("flow_id") String id) {
- if (!service.hasFlowClassifier(FlowClassifierId.of(UUID.fromString(id)))) {
+ if (!service.hasFlowClassifier(FlowClassifierId.of(id))) {
return Response.status(NOT_FOUND).entity(FLOW_CLASSIFIER_NOT_FOUND).build();
}
- FlowClassifier flowClassifier = nullIsNotFound(
- service.getFlowClassifier(FlowClassifierId.of(UUID.fromString(id))),
+ FlowClassifier flowClassifier = nullIsNotFound(service.getFlowClassifier(FlowClassifierId.of(id)),
FLOW_CLASSIFIER_NOT_FOUND);
ObjectNode result = new ObjectMapper().createObjectNode();
result.set("flow_classifier", new FlowClassifierCodec().encode(flowClassifier, this));
- return ok(result.toString()).build();
- }
- /**
- * Creates and stores a new flow classifier.
- *
- * @param flowClassifierId flow classifier identifier
- * @param stream flow classifier from JSON
- * @return status of the request - CREATED if the JSON is correct,
- * BAD_REQUEST if the JSON is invalid
- */
- @POST
- @Path("{flow_id}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response createFlowClassifier(@PathParam("flow_id") String flowClassifierId, InputStream stream) {
- URI location;
- try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-
- FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this);
- service.createFlowClassifier(flowClassifier);
- location = new URI(flowClassifierId);
- } catch (IOException | URISyntaxException ex) {
- throw new IllegalArgumentException(ex);
- }
- return Response.created(location).build();
+ return ok(result.toString()).build();
}
/**
@@ -125,32 +104,32 @@ public class FlowClassifierWebResource extends AbstractWebResource {
*
* @param stream flow classifier from JSON
* @return status of the request - CREATED if the JSON is correct,
- * BAD_REQUEST if the JSON is invalid
+ * BAD_REQUEST if the JSON is invalid
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createFlowClassifier(InputStream stream) {
- URI location;
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-
- FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this);
- service.createFlowClassifier(flowClassifier);
- location = new URI(flowClassifier.flowClassifierId().toString());
- } catch (IOException | URISyntaxException ex) {
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+ JsonNode flow = jsonTree.get("flow_classifier");
+
+ FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this);
+ Boolean issuccess = nullIsNotFound(service.createFlowClassifier(flowClassifier), FLOW_CLASSIFIER_NOT_FOUND);
+ return Response.status(OK).entity(issuccess.toString()).build();
+ } catch (IOException ex) {
+ log.error("Exception while creating flow classifier {}.", ex.toString());
throw new IllegalArgumentException(ex);
}
- return Response.created(location).build();
}
/**
- * Update details of a flow classifier. Update details of a specified flow
- * classifier id.
+ * Update details of a flow classifier.
*
* @param id flow classifier id
* @param stream InputStream
- * @return 200 OK
+ * @return 200 OK, 404 if given identifier does not exist
*/
@PUT
@Path("{flow_id}")
@@ -158,35 +137,29 @@ public class FlowClassifierWebResource extends AbstractWebResource {
@Consumes(MediaType.APPLICATION_JSON)
public Response updateFlowClassifier(@PathParam("flow_id") String id, final InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
- FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this);
+
+ JsonNode jsonTree = mapper().readTree(stream);
+ JsonNode flow = jsonTree.get("flow_classifier");
+ FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this);
Boolean result = nullIsNotFound(service.updateFlowClassifier(flowClassifier), FLOW_CLASSIFIER_NOT_FOUND);
- if (!result) {
- return Response.status(204).entity(FLOW_CLASSIFIER_NOT_FOUND).build();
- }
- return Response.status(203).entity(result.toString()).build();
- } catch (Exception e) {
- return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
+ return Response.status(OK).entity(result.toString()).build();
+ } catch (IOException e) {
+ log.error("Update flow classifier failed because of exception {}.", e.toString());
+ throw new IllegalArgumentException(e);
}
}
/**
- * Delete details of a flow classifier. Delete details of a specified flow
- * classifier id.
+ * Delete details of a flow classifier.
*
* @param id flow classifier id
- * @return 200 OK
- * @throws IOException when input doesn't match.
*/
@Path("{flow_id}")
@DELETE
- public Response deleteFlowClassifier(@PathParam("flow_id") String id) throws IOException {
- try {
- FlowClassifierId flowClassifierId = FlowClassifierId.of(UUID.fromString(id));
- service.removeFlowClassifier(flowClassifierId);
- return Response.status(201).entity("SUCCESS").build();
- } catch (Exception e) {
- return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build();
- }
+ public void deleteFlowClassifier(@PathParam("flow_id") String id) {
+ log.debug("Deletes flow classifier by identifier {}.", id);
+ FlowClassifierId flowClassifierId = FlowClassifierId.of(id);
+ Boolean issuccess = nullIsNotFound(service.removeFlowClassifier(flowClassifierId), FLOW_CLASSIFIER_NOT_FOUND);
+
}
}
diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
index 8bf459c2..b9012898 100644
--- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
+++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java
@@ -42,7 +42,9 @@ import org.onosproject.vtnweb.web.PortPairCodec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
/**
@@ -67,8 +69,13 @@ public class PortPairWebResource extends AbstractWebResource {
public Response getPortPairs() {
Iterable<PortPair> portPairs = service.getPortPairs();
ObjectNode result = new ObjectMapper().createObjectNode();
- result.set("port_pairs", new PortPairCodec().encode(portPairs, this));
- return ok(result).build();
+ ArrayNode portPairEntry = result.putArray("port_pairs");
+ if (portPairs != null) {
+ for (final PortPair portPair : portPairs) {
+ portPairEntry.add(new PortPairCodec().encode(portPair, this));
+ }
+ }
+ return ok(result.toString()).build();
}
/**
@@ -80,18 +87,15 @@ public class PortPairWebResource extends AbstractWebResource {
@GET
@Path("{pair_id}")
@Produces(MediaType.APPLICATION_JSON)
- public Response getPortPair(@PathParam("portPairId") String id) {
+ public Response getPortPair(@PathParam("pair_id") String id) {
if (!service.exists(PortPairId.of(id))) {
- return Response.status(NOT_FOUND)
- .entity(PORT_PAIR_NOT_FOUND).build();
+ return Response.status(NOT_FOUND).entity(PORT_PAIR_NOT_FOUND).build();
}
- PortPair portPair = nullIsNotFound(service.getPortPair(PortPairId.of(id)),
- PORT_PAIR_NOT_FOUND);
-
+ PortPair portPair = nullIsNotFound(service.getPortPair(PortPairId.of(id)), PORT_PAIR_NOT_FOUND);
ObjectNode result = new ObjectMapper().createObjectNode();
result.set("port_pair", new PortPairCodec().encode(portPair, this));
- return ok(result).build();
+ return ok(result.toString()).build();
}
/**
@@ -106,11 +110,11 @@ public class PortPairWebResource extends AbstractWebResource {
@Produces(MediaType.APPLICATION_JSON)
public Response createPortPair(InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
-
- PortPair portPair = codec(PortPair.class).decode(jsonTree, this);
- Boolean isSuccess = nullIsNotFound(service.createPortPair(portPair),
- PORT_PAIR_NOT_FOUND);
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+ JsonNode port = jsonTree.get("port_pair");
+ PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this);
+ Boolean isSuccess = nullIsNotFound(service.createPortPair(portPair), PORT_PAIR_NOT_FOUND);
return Response.status(OK).entity(isSuccess.toString()).build();
} catch (IOException e) {
log.error("Exception while creating port pair {}.", e.toString());
@@ -132,8 +136,10 @@ public class PortPairWebResource extends AbstractWebResource {
public Response updatePortPair(@PathParam("pair_id") String id,
final InputStream stream) {
try {
- ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
- PortPair portPair = codec(PortPair.class).decode(jsonTree, this);
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream);
+ JsonNode port = jsonTree.get("port_pair");
+ PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this);
Boolean isSuccess = nullIsNotFound(service.updatePortPair(portPair), PORT_PAIR_NOT_FOUND);
return Response.status(OK).entity(isSuccess.toString()).build();
} catch (IOException e) {
@@ -152,8 +158,7 @@ public class PortPairWebResource extends AbstractWebResource {
public void deletePortPair(@PathParam("pair_id") String id) {
PortPairId portPairId = PortPairId.of(id);
- Boolean isSuccess = nullIsNotFound(service.removePortPair(portPairId),
- PORT_PAIR_NOT_FOUND);
+ Boolean isSuccess = nullIsNotFound(service.removePortPair(portPairId), PORT_PAIR_NOT_FOUND);
if (!isSuccess) {
log.debug("Port pair identifier {} does not exist", id);
}
diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java
index 4c17633c..a18ca362 100644
--- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java
+++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java
@@ -18,16 +18,14 @@ package org.onosproject.vtnweb.web;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
-import java.util.UUID;
-
import org.onlab.packet.IpPrefix;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.vtnrsc.DefaultFlowClassifier;
import org.onosproject.vtnrsc.FlowClassifier;
import org.onosproject.vtnrsc.FlowClassifierId;
-import org.onosproject.vtnrsc.VirtualPortId;
import org.onosproject.vtnrsc.TenantId;
+import org.onosproject.vtnrsc.VirtualPortId;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -40,7 +38,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
private static final String TENANT_ID = "tenant_id";
private static final String NAME = "name";
private static final String DESCRIPTION = "description";
- private static final String ETHER_TYPE = "etherType";
+ private static final String ETHER_TYPE = "ethertype";
private static final String PROTOCOL = "protocol";
private static final String MIN_SRC_PORT_RANGE = "source_port_range_min";
private static final String MAX_SRC_PORT_RANGE = "source_port_range_max";
@@ -62,7 +60,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID),
FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText();
- resultBuilder.setFlowClassifierId(FlowClassifierId.of(UUID.fromString(flowClassifierId)));
+ resultBuilder.setFlowClassifierId(FlowClassifierId.of(flowClassifierId));
String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setTenantId(TenantId.tenantId(tenantId));
@@ -70,44 +68,46 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
String flowClassiferName = nullIsIllegal(json.get(NAME), NAME + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setName(flowClassiferName);
- String flowClassiferDescription = nullIsIllegal(json.get(DESCRIPTION), DESCRIPTION + MISSING_MEMBER_MESSAGE)
- .asText();
+ String flowClassiferDescription = (json.get(DESCRIPTION)).asText();
resultBuilder.setDescription(flowClassiferDescription);
String etherType = nullIsIllegal(json.get(ETHER_TYPE), ETHER_TYPE + MISSING_MEMBER_MESSAGE).asText();
resultBuilder.setEtherType(etherType);
- String protocol = nullIsIllegal(json.get(PROTOCOL), PROTOCOL + MISSING_MEMBER_MESSAGE).asText();
+ String protocol = (json.get(PROTOCOL)).asText();
resultBuilder.setProtocol(protocol);
- int minSrcPortRange = nullIsIllegal(json.get(MIN_SRC_PORT_RANGE), MIN_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE)
- .asInt();
+ int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt();
resultBuilder.setMinSrcPortRange(minSrcPortRange);
- int maxSrcPortRange = nullIsIllegal(json.get(MAX_SRC_PORT_RANGE), MAX_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE)
- .asInt();
+ int maxSrcPortRange = (json.get(MAX_SRC_PORT_RANGE)).asInt();
resultBuilder.setMaxSrcPortRange(maxSrcPortRange);
- int minDstPortRange = nullIsIllegal(json.get(MIN_DST_PORT_RANGE), MIN_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE)
- .asInt();
+ int minDstPortRange = (json.get(MIN_DST_PORT_RANGE)).asInt();
resultBuilder.setMinDstPortRange(minDstPortRange);
- int maxDstPortRange = nullIsIllegal(json.get(MAX_DST_PORT_RANGE), MAX_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE)
- .asInt();
+ int maxDstPortRange = (json.get(MAX_DST_PORT_RANGE)).asInt();
resultBuilder.setMaxDstPortRange(maxDstPortRange);
- String srcIpPrefix = nullIsIllegal(json.get(SRC_IP_PREFIX), SRC_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText();
- resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix));
-
- String dstIpPrefix = nullIsIllegal(json.get(DST_IP_PREFIX), DST_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText();
- resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix));
+ String srcIpPrefix = (json.get(SRC_IP_PREFIX)).asText();
+ if (!srcIpPrefix.isEmpty()) {
+ resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix));
+ }
- String srcPort = nullIsIllegal(json.get(SRC_PORT), SRC_PORT + MISSING_MEMBER_MESSAGE).asText();
- resultBuilder.setSrcPort(VirtualPortId.portId(srcPort));
+ String dstIpPrefix = (json.get(DST_IP_PREFIX)).asText();
+ if (!dstIpPrefix.isEmpty()) {
+ resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix));
+ }
- String dstPort = nullIsIllegal(json.get(DST_PORT), DST_PORT + MISSING_MEMBER_MESSAGE).asText();
- resultBuilder.setDstPort(VirtualPortId.portId(dstPort));
+ String srcPort = json.get(SRC_PORT) != null ? (json.get(SRC_PORT)).asText() : "";
+ if (!srcPort.isEmpty()) {
+ resultBuilder.setSrcPort(VirtualPortId.portId(srcPort));
+ }
+ String dstPort = json.get(DST_PORT) != null ? (json.get(DST_PORT)).asText() : "";
+ if (!dstPort.isEmpty()) {
+ resultBuilder.setDstPort(VirtualPortId.portId(dstPort));
+ }
return resultBuilder.build();
}
@@ -115,20 +115,20 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> {
public ObjectNode encode(FlowClassifier flowClassifier, CodecContext context) {
checkNotNull(flowClassifier, "flowClassifier cannot be null");
ObjectNode result = context.mapper().createObjectNode()
- .put("FLOW_CLASSIFIER_ID", flowClassifier.flowClassifierId().toString())
- .put("TENANT_ID", flowClassifier.tenantId().toString())
- .put("NAME", flowClassifier.name())
- .put("DESCRIPTION", flowClassifier.description())
- .put("ETHER_TYPE", flowClassifier.etherType())
- .put("PROTOCOL", flowClassifier.protocol())
- .put("MIN_SRC_PORT_RANGE", flowClassifier.minSrcPortRange())
- .put("MAX_SRC_PORT_RANGE", flowClassifier.maxSrcPortRange())
- .put("MIN_DST_PORT_RANGE", flowClassifier.minDstPortRange())
- .put("MAX_DST_PORT_RANGE", flowClassifier.maxDstPortRange())
- .put("SRC_IP_PREFIX", flowClassifier.srcIpPrefix().toString())
- .put("DST_IP_PREFIX", flowClassifier.dstIpPrefix().toString())
- .put("SRC_PORT", flowClassifier.srcPort().toString())
- .put("DST_PORT", flowClassifier.dstPort().toString());
+ .put(FLOW_CLASSIFIER_ID, flowClassifier.flowClassifierId().toString())
+ .put(TENANT_ID, flowClassifier.tenantId().toString())
+ .put(NAME, flowClassifier.name())
+ .put(DESCRIPTION, flowClassifier.description())
+ .put(ETHER_TYPE, flowClassifier.etherType())
+ .put(PROTOCOL, flowClassifier.protocol())
+ .put(MIN_SRC_PORT_RANGE, flowClassifier.minSrcPortRange())
+ .put(MAX_SRC_PORT_RANGE, flowClassifier.maxSrcPortRange())
+ .put(MIN_DST_PORT_RANGE, flowClassifier.minDstPortRange())
+ .put(MAX_DST_PORT_RANGE, flowClassifier.maxDstPortRange())
+ .put(SRC_IP_PREFIX, flowClassifier.srcIpPrefix().toString())
+ .put(DST_IP_PREFIX, flowClassifier.dstIpPrefix().toString())
+ .put(SRC_PORT, flowClassifier.srcPort().toString())
+ .put(DST_PORT, flowClassifier.dstPort().toString());
return result;
}
}
diff --git a/framework/src/onos/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java b/framework/src/onos/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
deleted file mode 100644
index 1f686aeb..00000000
--- a/framework/src/onos/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java
+++ /dev/null
@@ -1,545 +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.xosintegration;
-
-import com.eclipsesource.json.JsonArray;
-import com.eclipsesource.json.JsonObject;
-import com.google.common.collect.Maps;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
-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.apache.felix.scr.annotations.Service;
-import org.onlab.packet.VlanId;
-import org.onlab.util.Tools;
-import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
-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.flowobjective.DefaultForwardingObjective;
-import org.onosproject.net.flowobjective.FlowObjectiveService;
-import org.onosproject.net.flowobjective.ForwardingObjective;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-
-import java.util.Dictionary;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-import static com.google.common.net.MediaType.JSON_UTF_8;
-import static java.net.HttpURLConnection.HTTP_CREATED;
-import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
-import static java.net.HttpURLConnection.HTTP_OK;
-import static org.slf4j.LoggerFactory.getLogger;
-
-
-/**
- * XOS interface application.
- */
-@Component(immediate = true)
-@Service
-public class OnosXOSIntegrationManager implements VoltTenantService {
- private static final String XOS_SERVER_ADDRESS_PROPERTY_NAME =
- "xosServerAddress";
- private static final String XOS_SERVER_PORT_PROPERTY_NAME =
- "xosServerPort";
- private static final String XOS_PROVIDER_SERVICE_PROPERTY_NAME =
- "xosProviderService";
-
- private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22";
- private static final int TEST_XOS_SERVER_PORT = 8000;
- private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/";
- private static final int TEST_XOS_PROVIDER_SERVICE = 1;
-
- private static final int PRIORITY = 50000;
- private static final DeviceId FABRIC_DEVICE_ID = DeviceId.deviceId("of:5e3e486e73000187");
- private static final PortNumber FABRIC_OLT_CONNECT_POINT = PortNumber.portNumber(2);
- private static final PortNumber FABRIC_VCPE_CONNECT_POINT = PortNumber.portNumber(3);
- private static final String FABRIC_CONTROLLER_ADDRESS = "10.0.3.136";
- private static final int FABRIC_SERVER_PORT = 8181;
- private static final String FABRIC_BASE_URI = "/onos/cordfabric/vlans/add";
-
- private static final DeviceId OLT_DEVICE_ID = DeviceId.deviceId("of:90e2ba82f97791e9");
- private static final int OLT_UPLINK_PORT = 129;
-
- private static final ConnectPoint FABRIC_PORT = new ConnectPoint(
- DeviceId.deviceId("of:000090e2ba82f974"),
- PortNumber.portNumber(2));
-
- private final Logger log = getLogger(getClass());
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected ComponentConfigService cfgService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected FlowObjectiveService flowObjectiveService;
-
- @Property(name = XOS_SERVER_ADDRESS_PROPERTY_NAME,
- value = TEST_XOS_SERVER_ADDRESS,
- label = "XOS Server address")
- protected String xosServerAddress = TEST_XOS_SERVER_ADDRESS;
-
- @Property(name = XOS_SERVER_PORT_PROPERTY_NAME,
- intValue = TEST_XOS_SERVER_PORT,
- label = "XOS Server port")
- protected int xosServerPort = TEST_XOS_SERVER_PORT;
-
- @Property(name = XOS_PROVIDER_SERVICE_PROPERTY_NAME,
- intValue = TEST_XOS_PROVIDER_SERVICE,
- label = "XOS Provider Service")
- protected int xosProviderService = TEST_XOS_PROVIDER_SERVICE;
-
- private ApplicationId appId;
- private Map<String, ConnectPoint> nodeToPort;
- private Map<Long, Short> portToVlan;
- private Map<ConnectPoint, String> portToSsid;
-
- @Activate
- public void activate(ComponentContext context) {
- log.info("XOS app is starting");
- cfgService.registerProperties(getClass());
- appId = coreService.registerApplication("org.onosproject.xosintegration");
-
- setupMap();
-
- readComponentConfiguration(context);
-
- log.info("XOS({}) started", appId.id());
- }
-
- @Deactivate
- public void deactivate() {
- cfgService.unregisterProperties(getClass(), false);
- log.info("XOS({}) stopped", appId.id());
- }
-
- @Modified
- public void modified(ComponentContext context) {
- readComponentConfiguration(context);
- }
-
- private void setupMap() {
- nodeToPort = Maps.newHashMap();
-
- nodeToPort.put("cordcompute01.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID,
- PortNumber.portNumber(4)));
-
- nodeToPort.put("cordcompute02.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID,
- PortNumber.portNumber(3)));
-
- portToVlan = Maps.newHashMap();
- portToVlan.putIfAbsent(1L, (short) 201);
- portToVlan.putIfAbsent(6L, (short) 401);
-
- portToSsid = Maps.newHashMap();
- portToSsid.put(new ConnectPoint(OLT_DEVICE_ID, PortNumber.portNumber(1)), "0");
- portToSsid.put(new ConnectPoint(FABRIC_DEVICE_ID, PortNumber.portNumber(6)), "1");
- }
-
- /**
- * Converts a JSON representation of a tenant into a tenant object.
- *
- * @param jsonTenant JSON object representing the tenant
- * @return volt tenant object
- */
- private VoltTenant jsonToTenant(JsonObject jsonTenant) {
- return VoltTenant.builder()
- .withHumanReadableName(jsonTenant.get("humanReadableName").asString())
- .withId(jsonTenant.get("id").asInt())
- .withProviderService(jsonTenant.get("provider_service").asInt())
- .withServiceSpecificId(jsonTenant.get("service_specific_id").asString())
- .withVlanId(jsonTenant.get("vlan_id").asString())
- .build();
- }
-
- /**
- * Converts a tenant object into a JSON string.
- *
- * @param tenant volt tenant object to convert
- * @return JSON string for the tenant
- */
- private String tenantToJson(VoltTenant tenant) {
- return "{"
- + "\"humanReadableName\": \"" + tenant.humanReadableName() + "\","
- + "\"id\": \"" + tenant.id() + "\","
- + "\"provider_service\": \"" + tenant.providerService() + "\","
- + "\"service_specific_id\": \"" + tenant.serviceSpecificId() + "\","
- + "\"vlan_id\": \"" + tenant.vlanId() + "\""
- + "}";
- }
-
- /**
- * Gets a client web resource builder for the base XOS REST API
- * with no additional URI.
- *
- * @return web resource builder
- * @deprecated in Cardinal Release
- */
- @Deprecated
- private WebResource.Builder getClientBuilder() {
- return getClientBuilder("");
- }
-
- /**
- * Gets a client web resource builder for the base XOS REST API
- * with an optional additional URI.
- *
- * @return web resource builder
- * @deprecated in Cardinal Release
- */
- @Deprecated
- private WebResource.Builder getClientBuilder(String uri) {
- String baseUrl = "http://" + xosServerAddress + ":"
- + Integer.toString(xosServerPort);
- Client client = Client.create();
- client.addFilter(new HTTPBasicAuthFilter("padmin@vicci.org", "letmein"));
- WebResource resource = client.resource(baseUrl
- + XOS_TENANT_BASE_URI + uri);
- return resource.accept(JSON_UTF_8.toString())
- .type(JSON_UTF_8.toString());
- }
-
- /**
- * Performs a REST GET operation on the base XOS REST URI.
- *
- * @return JSON string fetched by the GET operation
- * @deprecated in Cardinal Release
- */
- @Deprecated
- private String getRest() {
- return getRest("");
- }
-
- /**
- * Performs a REST GET operation on the base XOS REST URI with
- * an optional additional URI.
- *
- * @return JSON string fetched by the GET operation
- * @deprecated in Cardinal Release
- */
- @Deprecated
- private String getRest(String uri) {
- WebResource.Builder builder = getClientBuilder(uri);
- ClientResponse response = builder.get(ClientResponse.class);
-
- if (response.getStatus() != HTTP_OK) {
- log.info("REST GET request returned error code {}",
- response.getStatus());
- }
- String jsonString = response.getEntity(String.class);
- log.info("JSON read:\n{}", jsonString);
-
- return jsonString;
- }
-
- /**
- * Performs a REST POST operation of a json string on the base
- * XOS REST URI with an optional additional URI.
- *
- * @param json JSON string to post
- * @deprecated in Cardinal Release
- */
- @Deprecated
- private String postRest(String json) {
- WebResource.Builder builder = getClientBuilder();
- ClientResponse response;
-
- try {
- response = builder.post(ClientResponse.class, json);
- } catch (ClientHandlerException e) {
- log.warn("Unable to contact REST server: {}", e.getMessage());
- return "{ 'error' : 'oops no one home' }";
- }
-
- if (response.getStatus() != HTTP_CREATED) {
- log.info("REST POST request returned error code {}",
- response.getStatus());
- }
- return response.getEntity(String.class);
- }
-
- /**
- * Performs a REST DELETE operation on the base
- * XOS REST URI with an optional additional URI.
- *
- * @param uri optional additional URI
- * @deprecated in Cardinal Release
- */
- @Deprecated
- private void deleteRest(String uri) {
- WebResource.Builder builder = getClientBuilder(uri);
- ClientResponse response = builder.delete(ClientResponse.class);
-
- if (response.getStatus() != HTTP_NO_CONTENT) {
- log.info("REST DELETE request returned error code {}",
- response.getStatus());
- }
- }
-
- /**
- * Deletes the tenant with the given ID.
- *
- * @param tenantId ID of tenant to delete
- */
- private void deleteTenant(long tenantId) {
- deleteRest(Long.toString(tenantId));
- }
-
- @Override
- public Set<VoltTenant> getAllTenants() {
- String jsonString = getRest();
-
- JsonArray voltTenantItems = JsonArray.readFrom(jsonString);
-
- return IntStream.range(0, voltTenantItems.size())
- .mapToObj(index -> jsonToTenant(voltTenantItems.get(index).asObject()))
- .collect(Collectors.toSet());
- }
-
- @Override
- public void removeTenant(long id) {
- deleteTenant(id);
- }
-
- @Override
- public VoltTenant addTenant(VoltTenant newTenant) {
- long providerServiceId = newTenant.providerService();
- if (providerServiceId == -1) {
- providerServiceId = xosProviderService;
- }
-
- PortNumber onuPort = newTenant.port().port();
- VlanId subscriberVlan = VlanId.vlanId(portToVlan.get(onuPort.toLong()));
-
- VoltTenant tenantToCreate = VoltTenant.builder()
- .withProviderService(providerServiceId)
- .withServiceSpecificId(portToSsid.get(newTenant.port()))
- .withVlanId(String.valueOf(subscriberVlan.toShort()))
- .withPort(newTenant.port())
- .build();
- String json = tenantToJson(tenantToCreate);
-
-
- provisionVlanOnPort(OLT_DEVICE_ID, OLT_UPLINK_PORT, onuPort, subscriberVlan.toShort());
-
- String retJson = postRest(json);
-
- fetchCPELocation(tenantToCreate, retJson);
-
- return newTenant;
- }
-
- private void fetchCPELocation(VoltTenant newTenant, String jsonString) {
- JsonObject json = JsonObject.readFrom(jsonString);
-
- if (json.get("computeNodeName") != null) {
- ConnectPoint point = nodeToPort.get(json.get("computeNodeName").asString());
- //ConnectPoint fromPoint = newTenant.port();
- ConnectPoint oltPort = new ConnectPoint(FABRIC_DEVICE_ID, FABRIC_OLT_CONNECT_POINT);
-
- provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId())),
- point, oltPort);
- }
-
- }
-
- @Override
- public VoltTenant getTenant(long id) {
- String jsonString = getRest(Long.toString(id));
- JsonObject jsonTenant = JsonObject.readFrom(jsonString);
- if (jsonTenant.get("id") != null) {
- return jsonToTenant(jsonTenant);
- } else {
- return null;
- }
- }
-
- private void provisionVlanOnPort(DeviceId deviceId, int uplinkPort, PortNumber p, short vlanId) {
-
- TrafficSelector upstream = DefaultTrafficSelector.builder()
- .matchVlanId(VlanId.ANY)
- .matchInPort(p)
- .build();
-
- TrafficSelector downstream = DefaultTrafficSelector.builder()
- .matchVlanId(VlanId.vlanId(vlanId))
- .matchInPort(PortNumber.portNumber(uplinkPort))
- .build();
-
- TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
- .setVlanId(VlanId.vlanId(vlanId))
- .setOutput(PortNumber.portNumber(uplinkPort))
- .build();
-
- TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
- .popVlan()
- .setOutput(p)
- .build();
-
-
- ForwardingObjective upFwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(1000)
- .makePermanent()
- .withSelector(upstream)
- .fromApp(appId)
- .withTreatment(upstreamTreatment)
- .add();
-
- ForwardingObjective downFwd = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(1000)
- .makePermanent()
- .withSelector(downstream)
- .fromApp(appId)
- .withTreatment(downstreamTreatment)
- .add();
-
- flowObjectiveService.forward(deviceId, upFwd);
- flowObjectiveService.forward(deviceId, downFwd);
-
- }
-
- private void provisionDataPlane(VoltTenant tenant) {
- VlanId vlan = VlanId.vlanId(Short.parseShort(tenant.vlanId()));
-
- TrafficSelector fromGateway = DefaultTrafficSelector.builder()
- .matchInPhyPort(tenant.port().port())
- .build();
-
- TrafficSelector fromFabric = DefaultTrafficSelector.builder()
- .matchInPhyPort(FABRIC_PORT.port())
- .matchVlanId(vlan)
- .build();
-
- TrafficTreatment toFabric = DefaultTrafficTreatment.builder()
- .pushVlan()
- .setVlanId(vlan)
- .setOutput(FABRIC_PORT.port())
- .build();
-
- TrafficTreatment toGateway = DefaultTrafficTreatment.builder()
- .popVlan()
- .setOutput(tenant.port().port())
- .build();
-
- ForwardingObjective forwardToFabric = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(PRIORITY)
- .makePermanent()
- .fromApp(appId)
- .withSelector(fromGateway)
- .withTreatment(toFabric)
- .add();
-
- ForwardingObjective forwardToGateway = DefaultForwardingObjective.builder()
- .withFlag(ForwardingObjective.Flag.VERSATILE)
- .withPriority(PRIORITY)
- .makePermanent()
- .fromApp(appId)
- .withSelector(fromFabric)
- .withTreatment(toGateway)
- .add();
-
- flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToFabric);
- flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToGateway);
- }
-
- private void provisionFabric(VlanId vlanId, ConnectPoint point, ConnectPoint fromPoint) {
-
- long vlan = vlanId.toShort();
-
- JsonObject node = new JsonObject();
- node.add("vlan", vlan);
- if (vlan == 201) {
- node.add("iptv", true);
- } else {
- node.add("iptv", false);
- }
- JsonArray array = new JsonArray();
- JsonObject cp1 = new JsonObject();
- JsonObject cp2 = new JsonObject();
- cp1.add("device", point.deviceId().toString());
- cp1.add("port", point.port().toLong());
- cp2.add("device", fromPoint.deviceId().toString());
- cp2.add("port", fromPoint.port().toLong());
- array.add(cp1);
- array.add(cp2);
- node.add("ports", array);
-
-
- String baseUrl = "http://" + FABRIC_CONTROLLER_ADDRESS + ":"
- + Integer.toString(FABRIC_SERVER_PORT);
- Client client = Client.create();
- WebResource resource = client.resource(baseUrl + FABRIC_BASE_URI);
- WebResource.Builder builder = resource.accept(JSON_UTF_8.toString())
- .type(JSON_UTF_8.toString());
-
- try {
- builder.post(ClientResponse.class, node.toString());
- } catch (ClientHandlerException e) {
- log.warn("Unable to contact fabric REST server: {}", e.getMessage());
- return;
- }
- }
-
- /**
- * Extracts properties from the component configuration context.
- *
- * @param context the component context
- */
- private void readComponentConfiguration(ComponentContext context) {
- Dictionary<?, ?> properties = context.getProperties();
-
- String newXosServerAddress =
- Tools.get(properties, XOS_SERVER_ADDRESS_PROPERTY_NAME);
- if (!isNullOrEmpty(newXosServerAddress)) {
- xosServerAddress = newXosServerAddress;
- }
-
- String newXosServerPortString =
- Tools.get(properties, XOS_SERVER_PORT_PROPERTY_NAME);
- if (!isNullOrEmpty(newXosServerPortString)) {
- xosServerPort = Integer.parseInt(newXosServerPortString);
- }
-
- String newXosProviderServiceString =
- Tools.get(properties, XOS_PROVIDER_SERVICE_PROPERTY_NAME);
- if (!isNullOrEmpty(newXosProviderServiceString)) {
- xosProviderService = Integer.parseInt(newXosProviderServiceString);
- }
- }
-}
-
-