diff options
Diffstat (limited to 'framework/src/onos/providers/ovsdb')
7 files changed, 169 insertions, 154 deletions
diff --git a/framework/src/onos/providers/ovsdb/app/pom.xml b/framework/src/onos/providers/ovsdb/app/pom.xml index 7bb506ba..b615d124 100644 --- a/framework/src/onos/providers/ovsdb/app/pom.xml +++ b/framework/src/onos/providers/ovsdb/app/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onosproject</groupId> <artifactId>onos-ovsdb-providers</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> diff --git a/framework/src/onos/providers/ovsdb/device/pom.xml b/framework/src/onos/providers/ovsdb/device/pom.xml index e5010fa6..8f9b834b 100644 --- a/framework/src/onos/providers/ovsdb/device/pom.xml +++ b/framework/src/onos/providers/ovsdb/device/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onosproject</groupId> <artifactId>onos-ovsdb-providers</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> </parent> <artifactId>onos-ovsdb-provider-device</artifactId> diff --git a/framework/src/onos/providers/ovsdb/host/pom.xml b/framework/src/onos/providers/ovsdb/host/pom.xml index 0bd88555..f54a496b 100644 --- a/framework/src/onos/providers/ovsdb/host/pom.xml +++ b/framework/src/onos/providers/ovsdb/host/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onosproject</groupId> <artifactId>onos-ovsdb-providers</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> </parent> <artifactId>onos-ovsdb-provider-host</artifactId> diff --git a/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java b/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java index 8d2fd142..0e3e1564 100644 --- a/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java +++ b/framework/src/onos/providers/ovsdb/host/src/main/java/org/onosproject/ovsdb/provider/host/OvsdbHostProvider.java @@ -1,148 +1,148 @@ -/*
- * 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.ovsdb.provider.host;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.toHex;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-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.packet.VlanId;
-import org.onosproject.core.CoreService;
-import org.onosproject.net.DefaultAnnotations;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Host;
-import org.onosproject.net.HostId;
-import org.onosproject.net.HostLocation;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.SparseAnnotations;
-import org.onosproject.net.host.DefaultHostDescription;
-import org.onosproject.net.host.HostDescription;
-import org.onosproject.net.host.HostProvider;
-import org.onosproject.net.host.HostProviderRegistry;
-import org.onosproject.net.host.HostProviderService;
-import org.onosproject.net.host.HostService;
-import org.onosproject.net.provider.AbstractProvider;
-import org.onosproject.net.provider.ProviderId;
-import org.onosproject.ovsdb.controller.EventSubject;
-import org.onosproject.ovsdb.controller.OvsdbController;
-import org.onosproject.ovsdb.controller.OvsdbEvent;
-import org.onosproject.ovsdb.controller.OvsdbEventListener;
-import org.onosproject.ovsdb.controller.OvsdbEventSubject;
-import org.slf4j.Logger;
-
-/**
- * Provider which uses an ovsdb controller to detect host.
- */
-@Component(immediate = true)
-@Service
-public class OvsdbHostProvider extends AbstractProvider implements HostProvider {
- private final Logger log = getLogger(getClass());
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostProviderRegistry providerRegistry;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected HostService hostService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected CoreService coreService;
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected OvsdbController controller;
-
- private HostProviderService providerService;
- private OvsdbEventListener innerEventListener = new InnerOvsdbEventListener();
-
- @Activate
- public void activate() {
- providerService = providerRegistry.register(this);
- controller.addOvsdbEventListener(innerEventListener);
- log.info("Started");
- }
-
- @Deactivate
- public void deactivate() {
- providerRegistry.unregister(this);
- providerService = null;
- log.info("Stopped");
- }
-
- public OvsdbHostProvider() {
- super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.host"));
- }
-
- @Override
- public void triggerProbe(Host host) {
- log.info("Triggering probe on host {}", host);
- }
-
- private class InnerOvsdbEventListener implements OvsdbEventListener {
-
- @Override
- public void handle(OvsdbEvent<EventSubject> event) {
- OvsdbEventSubject subject = null;
- if (event.subject() instanceof OvsdbEventSubject) {
- subject = (OvsdbEventSubject) event.subject();
- }
- checkNotNull(subject, "EventSubject is not null");
- // If ifaceid is null,it indicates this is not a vm port.
- if (subject.ifaceid() == null) {
- return;
- }
- switch (event.type()) {
- case PORT_ADDED:
- HostId hostId = HostId.hostId(subject.hwAddress(), null);
- DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value()));
- PortNumber portNumber = PortNumber.portNumber(subject
- .portNumber().value(), subject.portName().value());
- HostLocation loaction = new HostLocation(deviceId, portNumber,
- 0L);
- SparseAnnotations annotations = DefaultAnnotations.builder()
- .set("ifaceid", subject.ifaceid().value()).build();
- HostDescription hostDescription = new DefaultHostDescription(
- subject.hwAddress(),
- VlanId.vlanId(),
- loaction,
- annotations);
- providerService.hostDetected(hostId, hostDescription);
- break;
- case PORT_REMOVED:
- HostId host = HostId.hostId(subject.hwAddress(), null);
- providerService.hostVanished(host);
- break;
- default:
- break;
- }
-
- }
-
- }
-
- public URI uri(String value) {
- try {
- return new URI("of", toHex(Long.valueOf(value)), null);
- } catch (URISyntaxException e) {
- return null;
- }
- }
-}
+/* + * 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.ovsdb.provider.host; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.Tools.toHex; +import static org.slf4j.LoggerFactory.getLogger; + +import java.net.URI; +import java.net.URISyntaxException; + +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.packet.VlanId; +import org.onosproject.core.CoreService; +import org.onosproject.net.DefaultAnnotations; +import org.onosproject.net.DeviceId; +import org.onosproject.net.Host; +import org.onosproject.net.HostId; +import org.onosproject.net.HostLocation; +import org.onosproject.net.PortNumber; +import org.onosproject.net.SparseAnnotations; +import org.onosproject.net.host.DefaultHostDescription; +import org.onosproject.net.host.HostDescription; +import org.onosproject.net.host.HostProvider; +import org.onosproject.net.host.HostProviderRegistry; +import org.onosproject.net.host.HostProviderService; +import org.onosproject.net.host.HostService; +import org.onosproject.net.provider.AbstractProvider; +import org.onosproject.net.provider.ProviderId; +import org.onosproject.ovsdb.controller.EventSubject; +import org.onosproject.ovsdb.controller.OvsdbController; +import org.onosproject.ovsdb.controller.OvsdbEvent; +import org.onosproject.ovsdb.controller.OvsdbEventListener; +import org.onosproject.ovsdb.controller.OvsdbEventSubject; +import org.slf4j.Logger; + +/** + * Provider which uses an ovsdb controller to detect host. + */ +@Component(immediate = true) +@Service +public class OvsdbHostProvider extends AbstractProvider implements HostProvider { + private final Logger log = getLogger(getClass()); + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected HostProviderRegistry providerRegistry; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected HostService hostService; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected CoreService coreService; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected OvsdbController controller; + + private HostProviderService providerService; + private OvsdbEventListener innerEventListener = new InnerOvsdbEventListener(); + + @Activate + public void activate() { + providerService = providerRegistry.register(this); + controller.addOvsdbEventListener(innerEventListener); + log.info("Started"); + } + + @Deactivate + public void deactivate() { + providerRegistry.unregister(this); + providerService = null; + log.info("Stopped"); + } + + public OvsdbHostProvider() { + super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.host")); + } + + @Override + public void triggerProbe(Host host) { + log.info("Triggering probe on host {}", host); + } + + private class InnerOvsdbEventListener implements OvsdbEventListener { + + @Override + public void handle(OvsdbEvent<EventSubject> event) { + OvsdbEventSubject subject = null; + if (event.subject() instanceof OvsdbEventSubject) { + subject = (OvsdbEventSubject) event.subject(); + } + checkNotNull(subject, "EventSubject is not null"); + // If ifaceid is null,it indicates this is not a vm port. + if (subject.ifaceid() == null) { + return; + } + switch (event.type()) { + case PORT_ADDED: + HostId hostId = HostId.hostId(subject.hwAddress(), null); + DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value())); + PortNumber portNumber = PortNumber.portNumber(subject + .portNumber().value(), subject.portName().value()); + HostLocation loaction = new HostLocation(deviceId, portNumber, + 0L); + SparseAnnotations annotations = DefaultAnnotations.builder() + .set("ifaceid", subject.ifaceid().value()).build(); + HostDescription hostDescription = new DefaultHostDescription( + subject.hwAddress(), + VlanId.vlanId(), + loaction, + annotations); + providerService.hostDetected(hostId, hostDescription); + break; + case PORT_REMOVED: + HostId host = HostId.hostId(subject.hwAddress(), null); + providerService.hostVanished(host); + break; + default: + break; + } + + } + + } + + public URI uri(String value) { + try { + return new URI("of", toHex(Long.valueOf(value)), null); + } catch (URISyntaxException e) { + return null; + } + } +} diff --git a/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java b/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java index bf18606c..ad720c85 100644 --- a/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java +++ b/framework/src/onos/providers/ovsdb/host/src/test/java/org/onosproject/ovsdb/provider/host/OvsdbHostProviderTest.java @@ -143,7 +143,7 @@ public class OvsdbHostProviderTest { } @Override - public void hostDetected(HostId hostId, HostDescription hostDescription) { + public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { DeviceId descr = hostDescription.location().deviceId(); if (added == null) { added = descr; diff --git a/framework/src/onos/providers/ovsdb/pom.xml b/framework/src/onos/providers/ovsdb/pom.xml index bf215bc0..cce971d5 100644 --- a/framework/src/onos/providers/ovsdb/pom.xml +++ b/framework/src/onos/providers/ovsdb/pom.xml @@ -1,4 +1,19 @@ <?xml version="1.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. + --> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> @@ -7,7 +22,7 @@ <parent> <groupId>org.onosproject</groupId> <artifactId>onos-providers</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> </parent> <artifactId>onos-ovsdb-providers</artifactId> diff --git a/framework/src/onos/providers/ovsdb/tunnel/pom.xml b/framework/src/onos/providers/ovsdb/tunnel/pom.xml index 46ea585b..3eae2588 100644 --- a/framework/src/onos/providers/ovsdb/tunnel/pom.xml +++ b/framework/src/onos/providers/ovsdb/tunnel/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.onosproject</groupId> <artifactId>onos-ovsdb-providers</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> </parent> <artifactId>onos-ovsdb-provider-tunnel</artifactId> |