alshabib
Committed by Gerrit Code Review

null device provider implementation along with directory structure

for the other device providers

initial null provider directory structure

Change-Id: Ib7a766a854ba1863564ce2dc950f597a41a4e545

better with files

Change-Id: I041ea7bb718748e5f72ccaf06836c322b4e411d6

no binaries needed

Change-Id: I0bc978dd5bf6d20968bd1a28c6165b9f49ba585b

start nulldeviceprovider

Change-Id: If75bced900c185ca58a9302130c4d4a3cc18f12d

null device provider trivial implementation

supports hardcoded number of devices and ports, this will ultimately be extented to cli/rest configuration.

Change-Id: Iaeffc5526526b90fb1ecbcc0bd8b88103bdb921a
......@@ -118,6 +118,18 @@
<bundle>mvn:org.onosproject/onos-cli/@ONOS-VERSION</bundle>
</feature>
<feature name="onos-null" version="@FEATURE-VERSION"
description="ONOS Null providers">
<feature>onos-api</feature>
<bundle>mvn:org.onosproject/onos-null-provider-device/@ONOS-VERSION</bundle>
<bundle>mvn:org.onosproject/onos-null-provider-link/@ONOS-VERSION</bundle>
<bundle>mvn:org.onosproject/onos-null-provider-host/@ONOS-VERSION</bundle>
<bundle>mvn:org.onosproject/onos-null-provider-packet/@ONOS-VERSION</bundle>
<bundle>mvn:org.onosproject/onos-null-provider-flow/@ONOS-VERSION</bundle>
</feature>
<feature name="onos-openflow" version="@FEATURE-VERSION"
description="ONOS OpenFlow API, Controller &amp; Providers">
<feature>onos-api</feature>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-null-providers</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-null-provider-device</artifactId>
<packaging>bundle</packaging>
<description>ONOS Null protocol device provider</description>
</project>
/*
* 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.provider.nil.device.impl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
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.ChassisId;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.slf4j.Logger;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import static org.onlab.util.Tools.delay;
import static org.onlab.util.Tools.namedThreads;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provider which advertises fake/nonexistant devices to the core.
* To be used for benchmarking only.
*/
@Component(immediate = true)
public class NullDeviceProvider extends AbstractProvider implements DeviceProvider {
private static final Logger log = getLogger(NullDeviceProvider.class);
private static final String SCHEME = "null";
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry providerRegistry;
private DeviceProviderService providerService;
private ExecutorService deviceBuilder = Executors.newFixedThreadPool(1,
namedThreads("null-device-creator"));
//currently hardcoded. will be made configurable via rest/cli.
private static final int NUMDEVICES = 10;
private static final int NUMPORTSPERDEVICE = 10;
//Delay between events in ms.
private static final int EVENTINTERVAL = 5;
private final Map<Integer, DeviceDescription> descriptions = Maps.newHashMap();
private DeviceCreator creator;
/**
*
* Creates a provider with the supplier identifier.
*
*/
public NullDeviceProvider() {
super(new ProviderId("null", "org.onosproject.provider.nil"));
}
@Activate
public void activate() {
providerService = providerRegistry.register(this);
deviceBuilder.submit(new DeviceCreator(true));
log.info("Started");
}
@Deactivate
public void deactivate() {
deviceBuilder.submit(new DeviceCreator(false));
try {
deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
log.error("Device builder did not terminate");
}
deviceBuilder.shutdownNow();
providerRegistry.unregister(this);
providerService = null;
log.info("Stopped");
}
@Override
public void triggerProbe(DeviceId deviceId) {}
@Override
public void roleChanged(DeviceId deviceId, MastershipRole newRole) {}
@Override
public boolean isReachable(DeviceId deviceId) {
return descriptions.values().stream()
.anyMatch(desc -> desc.deviceURI().equals(deviceId.uri()));
}
private class DeviceCreator implements Runnable {
private boolean setup;
public DeviceCreator(boolean setup) {
this.setup = setup;
}
@Override
public void run() {
if (setup) {
advertiseDevices();
} else {
removeDevices();
}
}
private void removeDevices() {
for (DeviceDescription desc : descriptions.values()) {
providerService.deviceDisconnected(
DeviceId.deviceId(desc.deviceURI()));
delay(EVENTINTERVAL);
}
descriptions.clear();
}
private void advertiseDevices() {
DeviceId did;
ChassisId cid;
for (int i = 0; i < NUMDEVICES; i++) {
did = DeviceId.deviceId(String.format("%s:%d", SCHEME, i));
cid = new ChassisId(i);
DeviceDescription desc =
new DefaultDeviceDescription(did.uri(), Device.Type.SWITCH,
"ON.Lab", "0.0.1", "0.0.1", "1234",
cid);
descriptions.put(i, desc);
providerService.deviceConnected(did, desc);
providerService.updatePorts(did, buildPorts());
delay(EVENTINTERVAL);
}
}
private List<PortDescription> buildPorts() {
List<PortDescription> ports = Lists.newArrayList();
for (int i = 0; i < NUMPORTSPERDEVICE; i++) {
ports.add(new DefaultPortDescription(PortNumber.portNumber(i), true,
Port.Type.COPPER,
(long) 0));
}
return ports;
}
}
}
/*
* 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.
*/
/**
* Null Provider that advertises fake devices.
*/
package org.onosproject.provider.nil.device.impl;
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-null-providers</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-null-provider-flow</artifactId>
<packaging>bundle</packaging>
<description>ONOS Null protocol flow provider</description>
</project>
/*
* 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.
*/
/**
* Null provider that will accept any flow.
*/
package org.onosproject.provider.nil.flow.impl;
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-null-providers</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-null-provider-host</artifactId>
<packaging>bundle</packaging>
<description>ONOS Null host provider</description>
</project>
/*
* 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.
*/
/**
* Null Provider that advertises fake hosts.
*/
package org.onosproject.provider.nil.host.impl;
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-null-providers</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-null-provider-link</artifactId>
<packaging>bundle</packaging>
<description>ONOS Null link provider</description>
</project>
/*
* 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.
*/
/**
* Provider that advertises fake links.
*/
package org.onosproject.provider.nil.link.impl;
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-null-providers</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-null-provider-packet</artifactId>
<packaging>bundle</packaging>
<description>ONOS Null packet provider</description>
</project>
/*
* 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.
*/
/**
* Provider that takes and brings to/from oblivion.
*/
package org.onosproject.provider.nil.packet.impl;
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-providers</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-null-providers</artifactId>
<packaging>pom</packaging>
<description>ONOS null protocol adapters</description>
<modules>
<module>device</module>
<module>link</module>
<module>host</module>
<module>packet</module>
<module>flow</module>
</modules>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -35,6 +35,7 @@
<module>openflow</module>
<module>lldp</module>
<module>host</module>
<module>null</module>
</modules>
<dependencies>
......