Detangling incubator: virtual nets, tunnels, resource labels, oh my
- virtual networking moved to /apps/virtual; with CLI & REST API
- tunnels and labels moved to /apps/tunnel; with CLI & REST API; UI disabled for now
- protobuf/models moved to /core/protobuf/models
- defunct grpc/rpc registry stuff left under /graveyard
- compile dependencies on /incubator moved to respective modules for compilation
- run-time dependencies will need to be re-tested for dependent apps
- /graveyard will be removed in not-too-distant future
Change-Id: I0a0b995c635487edcf95a352f50dd162186b0b39
diff --git a/core/api/src/main/java/org/onosproject/alarm/Alarm.java b/core/api/src/main/java/org/onosproject/alarm/Alarm.java
new file mode 100644
index 0000000..1460cc7
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/Alarm.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.onosproject.net.DeviceId;
+
+/**
+ * Representation of an Alarm. At a given instant there can be only one alarm
+ * with the same deviceId + description + source combination.
+ */
+public interface Alarm {
+
+ /**
+ * Returns the unique alarm id within this ONOS instance.
+ *
+ * @return alarm identifier
+ */
+ AlarmId id();
+
+ /**
+ * The device to which this alarm is related.
+ *
+ * @return a device id
+ */
+ DeviceId deviceId();
+
+ /**
+ * Returns a description of alarm.
+ * <p>
+ * It may encapsulate Event Type as described by ITU Recommendation X.736
+ * ITU, Quoting https://tools.ietf.org/html/rfc3877 these include: other,
+ * communicationsAlarm, qualityOfServiceAlarm, processingErrorAlarm,
+ * equipmentAlarm, environmentalAlarm, integrityViolation,
+ * operationalViolation, physicalViolation,
+ * securityServiceOrMechanismViolation, timeDomainViolation
+ * <p>
+ * It may encapsulate Probable Cause as described by ITU Recommendation
+ * X.736 ITU, Quoting
+ * https://www.iana.org/assignments/ianaitualarmtc-mib/ianaitualarmtc-mib
+ * these include : aIS, callSetUpFailure, degradedSignal,
+ * farEndReceiverFailure, framingError, and hundreds more constants.
+ * <p>
+ * It may encapsulate a vendor-specific description of the underlying fault.
+ *
+ * @return description of alarm
+ */
+ String description();
+
+ /**
+ * Returns an entity within the context of this alarm's device. It may be
+ * null if deviceId sufficiently identifies the location. As an example, the
+ * source may indicate a port number
+ *
+ * @return source of alarm within the alarm's referenced Device.
+ */
+ AlarmEntityId source();
+
+ /**
+ * Returns the time when raised.
+ *
+ * @return time when raised, in milliseconds since start of epoch
+ */
+ long timeRaised();
+
+ /**
+ * Returns time at which the alarm was updated most recently, due to some
+ * change in the device, or ONOS. If the alarm has been cleared, this is the
+ * time at which the alarm was cleared.
+ *
+ * @return time when last updated, in milliseconds since start of epoch
+ */
+ long timeUpdated();
+
+ /**
+ * Returns the time when cleared. Null indicated no clear time, i.e. the
+ * alarm is still active.
+ *
+ * @return time when cleared, in milliseconds since start of epoch or null
+ * if uncleared.
+ */
+ Long timeCleared();
+
+ /**
+ * Returns the severity. Note, that cleared alarms may have EITHER
+ * SeverityLevel = CLEARED, or may be not present; both scenarios should be
+ * handled.
+ *
+ * @return severity of the alarm
+ */
+ SeverityLevel severity();
+
+ /**
+ * Returns true if alarm is service affecting Note: Whilst X.733 combines
+ * service-affecting state with severity (where severities of critical and
+ * major are deemed service-affecting) ONOS keeps these attributes separate.
+ *
+ * @return whether service affecting (true indicates it is)
+ */
+ boolean serviceAffecting();
+
+ /**
+ * Returns a flag to indicate if this alarm has been acknowledged. All
+ * alarms are unacknowledged until and unless an ONOS user takes action to
+ * indicate so.
+ *
+ * @return whether alarm is currently acknowledged (true indicates it is)
+ */
+ boolean acknowledged();
+
+ /**
+ * Returns a flag to indicate if this alarm has been cleared. All
+ * alarms are not cleared until and unless an ONOS user or app takes action to
+ * indicate so.
+ *
+ * @return whether alarm is currently cleared (true indicates it is)
+ */
+ default boolean cleared() {
+ return false;
+ }
+
+ /**
+ * Returns a flag to indicate if this alarm is manually-cleared by a user action within ONOS. Some stateless events
+ * e.g. backup-failure or upgrade-failure, may be mapped by ONOS to alarms, and these may be deemed manually-
+ * clearable. The more typical case is that an alarm represents a persistent fault on or related to a device and
+ * such alarms are never manually clearable, i.e. a configuration or operational state must occur for the alarm to
+ * clear.
+ *
+ * @return whether it may be cleared by a user action (true indicates it is)
+ */
+ boolean manuallyClearable();
+
+ /**
+ * Returns the user to whom this alarm is assigned; this is for future use
+ * and always returns null in this release. It is anticipated that in future ONOS
+ * releases, the existing JAAS user/key/role configuration will be extended
+ * to include a mechanism whereby some groups of users may allocate alarms
+ * to other users for bookkeeping and administrative purposes, and that ONOS
+ * will additionally provide a REST based mechanism, to retrieve from JAAS,
+ * the set of users to whom alarm assignment is possible for the current
+ * user.
+ *
+ * @return the assigned user; always null in this release.
+ */
+ String assignedUser();
+
+ /**
+ * Represents the severity level on an alarm, as per ITU-T X.733
+ * specifications.
+ * <p>
+ * The precedence is as follows for : Critical > Major > Minor > Warning.
+ */
+ enum SeverityLevel {
+
+ /**
+ * From X.733: This indicates the clearing of one or more previously
+ * reported alarms. This alarm clears all alarms for this managed object
+ * that have the same Alarm type, Probable cause and Specific problems
+ * (if given). Multiple associated notifications may be cleared by using
+ * the Correlated notifications parameter (defined below). This
+ * Recommendation | International Standard does not require that the
+ * clearing of previously reported alarms be reported. Therefore, a
+ * managing system cannot assume that the absence of an alarm with the
+ * Cleared severity level means that the condition that caused the
+ * generation of previous alarms is still present. Managed object
+ * definers shall state if, and under which conditions, the Cleared
+ * severity level is used.
+ */
+ CLEARED,
+ /**
+ * From X.733: This indicates that the severity level cannot be
+ * determined.
+ */
+ INDETERMINATE,
+ /**
+ * From X.733: This indicates that a service affecting condition has
+ * occurred and an immediate corrective action is required. Such a
+ * severity can be reported, for example, when a managed object becomes
+ * totally out of service and its capability must be restored.
+ */
+ CRITICAL,
+ /**
+ * X.733 definition: This indicates that a service affecting condition
+ * has developed and an urgent corrective action is required. Such a
+ * severity can be reported, for example, when there is a severe
+ * degradation in the capability of the managed object and its full
+ * capability must be restored.
+ */
+ MAJOR,
+ /**
+ * From X.733: This indicates the existence of a non-service affecting
+ * fault condition and that corrective action should be taken in order
+ * to prevent a more serious (for example, service affecting) fault.
+ * Such a severity can be reported, for example, when the detected alarm
+ * condition is not currently degrading the capacity of the managed
+ * object.
+ */
+ MINOR,
+ /**
+ * From X.733: This indicates the detection of a potential or impending
+ * service affecting fault, before any significant effects have been
+ * felt. Action should be taken to further diagnose (if necessary) and
+ * correct the problem in order to prevent it from becoming a more
+ * serious service affecting fault.
+ */
+ WARNING
+
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmConsumer.java b/core/api/src/main/java/org/onosproject/alarm/AlarmConsumer.java
new file mode 100644
index 0000000..d791c07
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmConsumer.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.alarm;
+
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.List;
+
+/**
+ * Abstraction of a device behaviour capable of retrieving/consuming list of
+ * pending alarms from the device.
+ */
+public interface AlarmConsumer extends HandlerBehaviour {
+
+ /**
+ * Returns the list of active alarms consumed from the device.
+ * This means that subsequent retrieval of alarms will not contain
+ * any duplicates.
+ *
+ * @return list of alarms consumed from the device
+ */
+ List<Alarm> consumeAlarms();
+
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmEntityId.java b/core/api/src/main/java/org/onosproject/alarm/AlarmEntityId.java
new file mode 100644
index 0000000..9debd0a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmEntityId.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import com.google.common.collect.ImmutableSet;
+import org.onlab.util.Identifier;
+
+import java.net.URI;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Immutable representation of a alarm source. It is meaningful within the
+ * context of a device.
+ */
+public final class AlarmEntityId extends Identifier<URI> {
+
+ public static final AlarmEntityId NONE = new AlarmEntityId(URI.create("none:none"));
+ public static final Set<String> SCHEMES = ImmutableSet.of("none", "port", "och", "other");
+
+ private AlarmEntityId(final URI uri) {
+ super(uri);
+ }
+
+ protected AlarmEntityId() {
+ super(NONE.identifier);
+ }
+
+ public static AlarmEntityId alarmEntityId(final String string) {
+ return alarmEntityId(URI.create(string));
+ }
+
+ public static AlarmEntityId alarmEntityId(final URI uri) {
+ checkArgument(SCHEMES.contains(uri.getScheme()), "Unexpected scheme");
+ return new AlarmEntityId(uri);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmEvent.java b/core/api/src/main/java/org/onosproject/alarm/AlarmEvent.java
new file mode 100644
index 0000000..376d110
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmEvent.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Entity that represents Alarm events. Note: although the event will itself have a time,
+ * consumers may be more interested in the times embedded in the alarms themselves.
+ */
+public class AlarmEvent extends AbstractEvent<AlarmEvent.Type, Alarm> {
+
+ /**
+ * Type of alarm event.
+ */
+ public enum Type {
+
+ /**
+ * Individual alarm updated.
+ */
+ CREATED,
+ /**
+ * Individual alarm updated.
+ */
+ UPDATED,
+ /**
+ * Alarm set updated for a given device.
+ */
+ REMOVED,
+ }
+
+ /**
+ * Creates an event due to one alarm.
+ *
+ * @param type alarm type
+ * @param alarm the alarm related to the event.
+ */
+ public AlarmEvent(AlarmEvent.Type type, Alarm alarm) {
+ super(type, alarm);
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmId.java b/core/api/src/main/java/org/onosproject/alarm/AlarmId.java
new file mode 100644
index 0000000..39cd5b6
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmId.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import com.google.common.annotations.Beta;
+import org.onlab.util.Identifier;
+import org.onosproject.net.DeviceId;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Alarm identifier suitable as an external key.
+ * <p>
+ * This class is immutable.</p>
+ */
+@Beta
+public final class AlarmId extends Identifier<String> {
+
+ /**
+ * Instantiates a new Alarm id.
+ *
+ * @param id the device id
+ * @param uniqueIdentifier the unique identifier of the Alarm on that device
+ */
+ private AlarmId(DeviceId id, String uniqueIdentifier) {
+ super(id.toString() + ":" + uniqueIdentifier);
+ checkNotNull(id, "device id must not be null");
+ checkNotNull(uniqueIdentifier, "unique identifier must not be null");
+ checkArgument(!uniqueIdentifier.isEmpty(), "unique identifier must not be empty");
+ }
+
+ /**
+ * Instantiates a new Alarm id, primarily meant for lookup.
+ *
+ * @param globallyUniqueIdentifier the globally unique identifier of the Alarm,
+ * device Id + local unique identifier on the device
+ */
+ private AlarmId(String globallyUniqueIdentifier) {
+ super(globallyUniqueIdentifier);
+ checkArgument(!globallyUniqueIdentifier.isEmpty(), "unique identifier must not be empty");
+ }
+
+ /**
+ * Creates an alarm identifier from the specified device id and
+ * unique identifier provided representation.
+ *
+ * @param id device id
+ * @param uniqueIdentifier per device unique identifier of the alarm
+ * @return alarm identifier
+ */
+ public static AlarmId alarmId(DeviceId id, String uniqueIdentifier) {
+ return new AlarmId(id, uniqueIdentifier);
+ }
+
+ /**
+ * Creates an alarm identifier from the specified globally unique identifier.
+ *
+ * @param globallyUniqueIdentifier the globally unique identifier of the Alarm,
+ * device Id + local unique identifier on the device
+ * @return alarm identifier
+ */
+ public static AlarmId alarmId(String globallyUniqueIdentifier) {
+ return new AlarmId(globallyUniqueIdentifier);
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmListener.java b/core/api/src/main/java/org/onosproject/alarm/AlarmListener.java
new file mode 100644
index 0000000..4977f66
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmListener.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.alarm;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving alarm related events.
+ */
+public interface AlarmListener extends EventListener<AlarmEvent> {
+}
\ No newline at end of file
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmProvider.java b/core/api/src/main/java/org/onosproject/alarm/AlarmProvider.java
new file mode 100644
index 0000000..14c20b3
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmProvider.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.Provider;
+
+/**
+ * Abstraction of an entity capable of supplying alarms collected from
+ * network devices.
+ */
+public interface AlarmProvider extends Provider {
+
+ /**
+ * Triggers an asynchronous discovery of the alarms on the specified device,
+ * intended to refresh internal alarm model for the device. An indirect
+ * result of this should be a event sent later with discovery result
+ * ie a set of alarms.
+ *
+ * @param deviceId ID of device to be probed
+ */
+ void triggerProbe(DeviceId deviceId);
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmProviderRegistry.java b/core/api/src/main/java/org/onosproject/alarm/AlarmProviderRegistry.java
new file mode 100644
index 0000000..32e812d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmProviderRegistry.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+
+import org.onosproject.net.provider.ProviderRegistry;
+
+/**
+ * Abstraction of a alarm provider registry.
+ */
+public interface AlarmProviderRegistry extends ProviderRegistry<AlarmProvider, AlarmProviderService> {
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmProviderService.java b/core/api/src/main/java/org/onosproject/alarm/AlarmProviderService.java
new file mode 100644
index 0000000..674c0b1
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmProviderService.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderService;
+
+import java.util.Collection;
+
+/**
+ * The interface Alarm provider service.
+ */
+
+public interface AlarmProviderService extends ProviderService<AlarmProvider> {
+
+ /**
+ * Sends active alarm list for a device.
+ *
+ * @param deviceId identity of the device
+ * @param alarms list of device alarms
+ */
+ void updateAlarmList(DeviceId deviceId, Collection<Alarm> alarms);
+
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmService.java b/core/api/src/main/java/org/onosproject/alarm/AlarmService.java
new file mode 100644
index 0000000..7be4d80
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmService.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.onosproject.event.ListenerService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Service for interacting with the alarm handling of devices. Unless stated otherwise, getter methods
+ * return active AND recently-cleared alarms.
+ */
+public interface AlarmService extends ListenerService<AlarmEvent, AlarmListener> {
+
+ /**
+ * Update book-keeping (ie administrative) fields for the alarm matching the specified identifier.
+ *
+ * @param id alarm identifier
+ * @param clear true if the alarm has to be cleared
+ * @param isAcknowledged new acknowledged state
+ * @param assignedUser new assigned user, null clear
+ * @return updated alarm (including any recent device-derived changes)
+ */
+ Alarm updateBookkeepingFields(AlarmId id, boolean clear, boolean isAcknowledged, String assignedUser);
+
+ /**
+ * Remove an alarm from ONOS.
+ *
+ * @param id alarm
+ */
+ void remove(AlarmId id);
+
+ /**
+ * Returns summary of alarms on a given device.
+ *
+ * @param deviceId the device
+ * @return map of severity (if applicable) vs alarm counts; empty map if either the device has no alarms or
+ * identified device is not managed.
+ */
+ Map<Alarm.SeverityLevel, Long> getAlarmCounts(DeviceId deviceId);
+
+ /**
+ * Returns summary of alarms on all devices.
+ *
+ * @return map of severity (if applicable) vs alarm counts; empty map if no alarms.
+ */
+ Map<Alarm.SeverityLevel, Long> getAlarmCounts();
+
+ /**
+ * Returns the alarm with the specified identifier.
+ *
+ * @param alarmId alarm identifier
+ * @return alarm matching id; null if no alarm matches the identifier.
+ */
+ Alarm getAlarm(AlarmId alarmId);
+
+ /**
+ * Returns all of the alarms.
+ *
+ * @return set of alarms; empty set if no alarms
+ */
+ Set<Alarm> getAlarms();
+
+ /**
+ * Returns all of the ACTIVE alarms. Recently cleared alarms excluded.
+ *
+ * @return set of alarms; empty set if no alarms
+ */
+ Set<Alarm> getActiveAlarms();
+
+ /**
+ * Returns the alarms with the specified severity.
+ *
+ * @param severity the alarm severity
+ * @return set of alarms with a particular severity; empty set if no alarms
+ */
+ Set<Alarm> getAlarms(Alarm.SeverityLevel severity);
+
+ /**
+ * Returns the alarm matching a given device, regardless of source within that device.
+ *
+ * @param deviceId the device to use when searching alarms.
+ * @return set of alarms; empty set if no alarms
+ */
+ Set<Alarm> getAlarms(DeviceId deviceId);
+
+ /**
+ * Returns all of the ACTIVE alarms for a specific device. Recently cleared alarms excluded.
+ *
+ * @param deviceId the device to use when searching alarms.
+ * @return set of alarms; empty set if no alarms
+ */
+ default Set<Alarm> getActiveAlarms(DeviceId deviceId) {
+ return getActiveAlarms().stream()
+ .filter(a -> deviceId.equals(a.deviceId()))
+ .collect(Collectors.toSet());
+ }
+
+ /**
+ * Returns the alarm for a given device and source.
+ *
+ * @param deviceId the device
+ * @param source the source within the device
+ * @return set of alarms; empty set if no alarms
+ */
+ Set<Alarm> getAlarms(DeviceId deviceId, AlarmEntityId source);
+
+ /**
+ * Returns the alarm affecting a given link.
+ *
+ * @param src one end of the link
+ * @param dst one end of the link
+ * @return set of alarms; empty set if no alarms
+ */
+ Set<Alarm> getAlarmsForLink(ConnectPoint src, ConnectPoint dst);
+
+ /**
+ * Returns the alarm affecting a given flow.
+ *
+ * @param deviceId the device
+ * @param flowId the flow
+ * @return set of alarms; empty set if no alarms
+ */
+ Set<Alarm> getAlarmsForFlow(DeviceId deviceId, long flowId);
+
+ // TODO Support retrieving alarms affecting other entity types may be added in future release
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/AlarmTranslator.java b/core/api/src/main/java/org/onosproject/alarm/AlarmTranslator.java
new file mode 100644
index 0000000..ad29535
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/AlarmTranslator.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.alarm;
+
+import org.onosproject.net.DeviceId;
+
+import java.io.InputStream;
+import java.util.Collection;
+
+/**
+ * Abstraction of ability to translate device messages into alarms.
+ */
+public interface AlarmTranslator {
+
+ /**
+ * Translates message from device into an alarm with appropriate
+ * information.
+ *
+ * @param deviceId device
+ * @param message message from device to translate to alarm
+ * @return Alarm with information determined by given message
+ */
+ Collection<Alarm> translateToAlarm(DeviceId deviceId, InputStream message);
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/DefaultAlarm.java b/core/api/src/main/java/org/onosproject/alarm/DefaultAlarm.java
new file mode 100644
index 0000000..278be4b
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/DefaultAlarm.java
@@ -0,0 +1,401 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.onosproject.net.DeviceId;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default implementation of an alarm.
+ */
+public final class DefaultAlarm implements Alarm {
+
+ private final AlarmId id;
+
+ private final DeviceId deviceId;
+ private final String description;
+ private final AlarmEntityId source;
+ private final long timeRaised;
+ private final boolean isServiceAffecting;
+ private final boolean isAcknowledged;
+ private final boolean isManuallyClearable;
+ private final String assignedUser;
+
+ private final SeverityLevel severity;
+ private final long timeUpdated;
+ private final Long timeCleared;
+
+
+ //Only for Kryo
+ DefaultAlarm() {
+ id = null;
+ deviceId = null;
+ description = null;
+ source = null;
+ timeRaised = -1;
+ timeUpdated = -1;
+ timeCleared = null;
+ severity = null;
+ isServiceAffecting = false;
+ isAcknowledged = false;
+ isManuallyClearable = false;
+ assignedUser = null;
+ }
+
+ /**
+ * Instantiates a new Default alarm.
+ *
+ * @param id the id
+ * @param deviceId the device id
+ * @param description the description
+ * @param source the source, null indicates none.
+ * @param timeRaised the time raised.
+ * @param timeUpdated the time last updated.
+ * @param timeCleared the time cleared, null indicates uncleared.
+ * @param severity the severity
+ * @param isServiceAffecting the service affecting
+ * @param isAcknowledged the acknowledged
+ * @param isManuallyClearable the manually clearable
+ * @param assignedUser the assigned user, `null` indicates none.
+ */
+ private DefaultAlarm(final AlarmId id,
+ final DeviceId deviceId,
+ final String description,
+ final AlarmEntityId source,
+ final long timeRaised,
+ final long timeUpdated,
+ final Long timeCleared,
+ final SeverityLevel severity,
+ final boolean isServiceAffecting,
+ final boolean isAcknowledged,
+ final boolean isManuallyClearable,
+ final String assignedUser) {
+ this.id = id;
+ this.deviceId = deviceId;
+ this.description = description;
+ this.source = source;
+ this.timeRaised = timeRaised;
+ this.timeUpdated = timeUpdated;
+ this.timeCleared = timeCleared;
+ this.severity = severity;
+ this.isServiceAffecting = isServiceAffecting;
+ this.isAcknowledged = isAcknowledged;
+ this.isManuallyClearable = isManuallyClearable;
+ this.assignedUser = assignedUser;
+ }
+
+ @Override
+ public AlarmId id() {
+ return id;
+ }
+
+ @Override
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ @Override
+ public String description() {
+ return description;
+ }
+
+ @Override
+ public AlarmEntityId source() {
+ return source;
+ }
+
+ @Override
+ public long timeRaised() {
+ return timeRaised;
+ }
+
+ @Override
+ public long timeUpdated() {
+ return timeUpdated;
+ }
+
+ @Override
+ public Long timeCleared() {
+ return timeCleared;
+ }
+
+ @Override
+ public SeverityLevel severity() {
+ return severity;
+ }
+
+ @Override
+ public boolean serviceAffecting() {
+ return isServiceAffecting;
+ }
+
+ @Override
+ public boolean acknowledged() {
+ return isAcknowledged;
+ }
+
+ @Override
+ public boolean cleared() {
+ return severity.equals(SeverityLevel.CLEARED);
+ }
+
+ @Override
+ public boolean manuallyClearable() {
+ return isManuallyClearable;
+ }
+
+ @Override
+ public String assignedUser() {
+ return assignedUser;
+ }
+
+ @Override
+ public int hashCode() {
+ // id or timeRaised or timeUpdated may differ
+ return Objects.hash(deviceId, description,
+ source, timeCleared, severity,
+ isServiceAffecting, isAcknowledged,
+ isManuallyClearable, assignedUser);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ // Make sure equals() is tune with hashCode() so works ok in a hashSet !
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final DefaultAlarm other = (DefaultAlarm) obj;
+
+ // id or timeRaised or timeUpdated may differ
+ if (!Objects.equals(this.deviceId, other.deviceId)) {
+ return false;
+ }
+ if (!Objects.equals(this.description, other.description)) {
+ return false;
+ }
+ if (!Objects.equals(this.source, other.source)) {
+ return false;
+ }
+
+ if (!Objects.equals(this.timeCleared, other.timeCleared)) {
+ return false;
+ }
+ if (this.severity != other.severity) {
+ return false;
+ }
+ if (this.isServiceAffecting != other.isServiceAffecting) {
+ return false;
+ }
+ if (this.isAcknowledged != other.isAcknowledged) {
+ return false;
+ }
+ if (this.isManuallyClearable != other.isManuallyClearable) {
+ return false;
+ }
+ if (!Objects.equals(this.assignedUser, other.assignedUser)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("id", id)
+ .add("deviceId", deviceId)
+ .add("description", description)
+ .add("source", source)
+ .add("timeRaised", timeRaised)
+ .add("timeUpdated", timeUpdated)
+ .add("timeCleared", timeCleared)
+ .add("severity", severity)
+ .add("serviceAffecting", isServiceAffecting)
+ .add("acknowledged", isAcknowledged)
+ .add("manuallyClearable", isManuallyClearable)
+ .add("assignedUser", assignedUser)
+ .toString();
+ }
+
+ /**
+ * Builder for the DefaultAlarm object.
+ */
+ public static class Builder {
+
+ // Manadatory fields when constructing alarm ...
+ private AlarmId id;
+ private final DeviceId deviceId;
+ private final String description;
+ private SeverityLevel severity;
+ private final long timeRaised;
+
+ // Optional fields ..
+ private AlarmEntityId source = AlarmEntityId.NONE;
+ private long timeUpdated;
+ private Long timeCleared = null;
+ private boolean isServiceAffecting = false;
+ private boolean isAcknowledged = false;
+ private boolean isManuallyClearable = false;
+ private String assignedUser = null;
+
+ /**
+ * Constructs a Builder to create a Default Alarm based on another alarm.
+ *
+ * @param alarm the other alarm
+ */
+ public Builder(final Alarm alarm) {
+ this(alarm.id(), alarm.deviceId(), alarm.description(), alarm.severity(), alarm.timeRaised());
+ this.source = alarm.source();
+ this.timeUpdated = alarm.timeUpdated();
+ this.timeCleared = alarm.timeCleared();
+ this.isServiceAffecting = alarm.serviceAffecting();
+ this.isAcknowledged = alarm.acknowledged();
+ this.isManuallyClearable = alarm.manuallyClearable();
+ this.assignedUser = alarm.assignedUser();
+
+ }
+
+ /**
+ * Constructs a Builder to create a Default Alarm.
+ *
+ * @param id the AlarmId
+ * @param deviceId the device ID
+ * @param description the Alarm description
+ * @param severity the severity
+ * @param timeRaised when the alarm was raised
+ */
+ public Builder(final AlarmId id, final DeviceId deviceId,
+ final String description, final SeverityLevel severity, final long timeRaised) {
+ super();
+ this.id = id;
+ this.deviceId = deviceId;
+ this.description = description;
+ this.severity = severity;
+ this.timeRaised = timeRaised;
+ // Unless specified time-updated is same as raised.
+ this.timeUpdated = timeRaised;
+ }
+
+ /**
+ * Sets the new alarm source.
+ *
+ * @param source the source
+ * @return self for chaining
+ */
+ public Builder forSource(final AlarmEntityId source) {
+ this.source = source;
+ return this;
+ }
+
+ /**
+ * Sets the new alarm time updated.
+ *
+ * @param timeUpdated the time
+ * @return self for chaining
+ */
+ public Builder withTimeUpdated(final long timeUpdated) {
+ this.timeUpdated = timeUpdated;
+ return this;
+ }
+
+ /**
+ * Sets the new alarm time cleared.
+ *
+ * @param timeCleared the time
+ * @return self for chaining
+ */
+ public Builder withTimeCleared(final Long timeCleared) {
+ this.timeCleared = timeCleared;
+ return this;
+ }
+
+ /**
+ * Clears the alarm that is being created.
+ *
+ * @return self for chaining
+ */
+ public Builder clear() {
+ this.severity = SeverityLevel.CLEARED;
+ final long now = System.currentTimeMillis();
+ return withTimeCleared(now).withTimeUpdated(now);
+ }
+
+ /**
+ * Sets the new alarm service affecting flag.
+ *
+ * @param isServiceAffecting the service affecting flag
+ * @return self for chaining
+ */
+ public Builder withServiceAffecting(final boolean isServiceAffecting) {
+ this.isServiceAffecting = isServiceAffecting;
+ return this;
+ }
+
+ /**
+ * Sets the new alarm acknowledged flag.
+ *
+ * @param isAcknowledged the acknowledged flag
+ * @return self for chaining
+ */
+ public Builder withAcknowledged(final boolean isAcknowledged) {
+ this.isAcknowledged = isAcknowledged;
+ return this;
+ }
+
+ /**
+ * Sets the new alarm the manually clearable flag.
+ *
+ * @param isManuallyClearable the manually clearable flag
+ * @return self for chaining
+ */
+ public Builder withManuallyClearable(final boolean isManuallyClearable) {
+ this.isManuallyClearable = isManuallyClearable;
+ return this;
+ }
+
+ /**
+ * Sets the new alarm assigned user.
+ *
+ * @param assignedUser the user
+ * @return self for chaining
+ */
+ public Builder withAssignedUser(final String assignedUser) {
+ this.assignedUser = assignedUser;
+ return this;
+ }
+
+ /**
+ * Builds the alarm.
+ *
+ * @return self for chaining
+ */
+ public DefaultAlarm build() {
+ checkNotNull(id, "Must specify an alarm id");
+ checkNotNull(deviceId, "Must specify a device");
+ checkNotNull(description, "Must specify a description");
+ checkNotNull(severity, "Must specify a severity");
+
+ return new DefaultAlarm(id, deviceId, description, source, timeRaised, timeUpdated, timeCleared,
+ severity, isServiceAffecting, isAcknowledged, isManuallyClearable, assignedUser);
+ }
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/DeviceAlarmConfig.java b/core/api/src/main/java/org/onosproject/alarm/DeviceAlarmConfig.java
new file mode 100644
index 0000000..8d6146f
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/DeviceAlarmConfig.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.alarm;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.net.driver.HandlerBehaviour;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Abstraction of a device behaviour capable of translating a list of
+ * alarms from a device. Also provides a method to configure the address where to
+ * send the alarms/traps/notifications.
+ */
+public interface DeviceAlarmConfig extends HandlerBehaviour {
+
+ /**
+ * Configures the device to send alarms to a particular Ip and port combination.
+ *
+ * @param address address to wich the device should send alarms
+ * @param port port on which the controller is listening
+ * @param protocol tcp or udp
+ * @return boolean true if the device was properly configured
+ */
+ boolean configureDevice(IpAddress address, int port, String protocol);
+
+ /**
+ * Returns the list of translated alarms from device-specific representation
+ * to ONOS alarms.
+ *
+ * @param unparsedAlarms alarms arrived from the device depending on protocol
+ * @param <T> type of object given from the device
+ * @return list of alarms consumed from the device
+ */
+ <T> Set<Alarm> translateAlarms(List<T> unparsedAlarms);
+
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/XmlEventParser.java b/core/api/src/main/java/org/onosproject/alarm/XmlEventParser.java
new file mode 100644
index 0000000..0154cb9
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/XmlEventParser.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.DateTimeException;
+import java.time.OffsetDateTime;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * Parser for Netconf notifications.
+ */
+public final class XmlEventParser {
+ public static final Logger log = LoggerFactory
+ .getLogger(XmlEventParser.class);
+
+ private static final String DISALLOW_DTD_FEATURE = "http://apache.org/xml/features/disallow-doctype-decl";
+ private static final String DISALLOW_EXTERNAL_DTD =
+ "http://apache.org/xml/features/nonvalidating/load-external-dtd";
+ private static final String EVENTTIME_TAGNAME = "eventTime";
+
+ private XmlEventParser() {
+ }
+
+ /**
+ * Creates a document from the input stream message and returns the result.
+ *
+ * @param message input stream message
+ * @return the document result
+ * @throws SAXException Throws SAX Exception
+ * @throws IOException Throws IO Exception
+ * @throws ParserConfigurationException Throws ParserConfigurationException
+ */
+ public static Document createDocFromMessage(InputStream message)
+ throws SAXException, IOException, ParserConfigurationException {
+ DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
+ //Disabling DTDs in order to avoid XXE xml-based attacks.
+ disableFeature(dbfactory, DISALLOW_DTD_FEATURE);
+ disableFeature(dbfactory, DISALLOW_EXTERNAL_DTD);
+ dbfactory.setXIncludeAware(false);
+ dbfactory.setExpandEntityReferences(false);
+ DocumentBuilder builder = dbfactory.newDocumentBuilder();
+ return builder.parse(new InputSource(message));
+ }
+
+ private static void disableFeature(DocumentBuilderFactory dbfactory, String feature) {
+ try {
+ dbfactory.setFeature(feature, true);
+ } catch (ParserConfigurationException e) {
+ // This should catch a failed setFeature feature
+ log.info("ParserConfigurationException was thrown. The feature '" +
+ feature + "' is probably not supported by your XML processor.");
+ }
+ }
+
+ public static long getEventTime(String dateTime)
+ throws UnsupportedOperationException, IllegalArgumentException {
+ try {
+ OffsetDateTime date = OffsetDateTime.parse(dateTime, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
+ return date.toInstant().toEpochMilli();
+ } catch (DateTimeException e) {
+ log.error("Cannot parse exception {} {}", dateTime, e);
+ }
+ return System.currentTimeMillis();
+ }
+
+ public static long getEventTime(Document doc)
+ throws UnsupportedOperationException, IllegalArgumentException {
+ String dateTime = getEventTimeNode(doc).getTextContent();
+ return getEventTime(dateTime);
+ }
+
+ public static Node getDescriptionNode(Document doc) {
+ return getEventTimeNode(doc).getNextSibling();
+ }
+
+ private static Node getEventTimeNode(Document doc) {
+ return doc.getElementsByTagName(EVENTTIME_TAGNAME).item(0);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/alarm/package-info.java b/core/api/src/main/java/org/onosproject/alarm/package-info.java
new file mode 100644
index 0000000..4003645
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/alarm/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Abstractions for interacting with alarms. An alarm is a persistent indication
+ * of a fault that clears only when the triggering condition has been resolved.
+ */
+package org.onosproject.alarm;
diff --git a/core/api/src/main/java/org/onosproject/net/TenantId.java b/core/api/src/main/java/org/onosproject/net/TenantId.java
new file mode 100644
index 0000000..1b8fadb
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/TenantId.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net;
+
+import org.onlab.util.Identifier;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * Representation of network tenant.
+ */
+public final class TenantId extends Identifier<String> {
+
+ /**
+ * Represents no tenant, or an unspecified tenant.
+ */
+ public static final TenantId NONE = new TenantId();
+
+ // Public construction is prohibited
+ private TenantId(String id) {
+ super(id);
+ checkArgument(id != null && id.length() > 0, "Tenant ID cannot be null or empty");
+ }
+
+ // Default constructor for serialization
+ protected TenantId() {
+ super("");
+ }
+
+ /**
+ * Creates a tenant id using the supplied backing id.
+ *
+ * @param id network id
+ * @return network identifier
+ */
+ public static TenantId tenantId(String id) {
+ return new TenantId(id);
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/PortDescriptionsConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/PortDescriptionsConfig.java
new file mode 100644
index 0000000..484660e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/PortDescriptionsConfig.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.config.basics;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Configuration for Ports. Creates a list of PortDescription based on the given Json.
+ */
+@Beta
+public class PortDescriptionsConfig extends Config<DeviceId> {
+ private static Logger log = LoggerFactory.getLogger(PortDescriptionsConfig.class);
+
+ private static final String NUMBER = "number";
+ private static final String NAME = "name";
+ private static final String ENABLED = "enabled";
+ private static final String REMOVED = "removed";
+ private static final String TYPE = "type";
+ private static final String SPEED = "speed";
+ private static final String ANNOTATIONS = "annotations";
+
+ private static final String CONFIG_VALUE_ERROR = "Error parsing config value";
+
+ @Override
+ public boolean isValid() {
+ for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
+ JsonNode nodePort = it.next().getValue();
+ if (!hasOnlyFields((ObjectNode) nodePort, NUMBER, NAME, ENABLED, REMOVED, TYPE,
+ SPEED, ANNOTATIONS)) {
+ return false;
+ }
+ ObjectNode obj = (ObjectNode) nodePort;
+
+ if (!(isNumber(obj, NUMBER, FieldPresence.MANDATORY) &&
+ isString(obj, NAME, FieldPresence.OPTIONAL) &&
+ isBoolean(obj, ENABLED, FieldPresence.OPTIONAL) &&
+ isBoolean(obj, REMOVED, FieldPresence.OPTIONAL) &&
+ isString(obj, TYPE, FieldPresence.OPTIONAL) &&
+ isIntegralNumber(obj, SPEED, FieldPresence.OPTIONAL))) {
+ return false;
+ }
+
+ if (node.has(ANNOTATIONS) && !node.get(ANNOTATIONS).isObject()) {
+ log.error("Annotations must be an inner json node");
+ return false;
+ }
+
+ }
+ return true;
+ }
+
+ /**
+ * Retrieves all port descriptions.
+ *
+ * @return set of port descriptions
+ */
+ public List<PortDescription> portDescriptions() {
+
+ try {
+ ImmutableList.Builder<PortDescription> portDescriptions = ImmutableList.builder();
+ for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
+ JsonNode portNode = it.next().getValue();
+ long number = portNode.path(NUMBER).asLong();
+
+ String name = portNode.path(NAME).asText(null);
+
+ PortNumber portNumber = createPortNumber(number, name);
+
+ DefaultPortDescription.Builder builder = DefaultPortDescription.builder()
+ .withPortNumber(portNumber);
+ if (portNode.has(ENABLED)) {
+ builder.isEnabled(portNode.path(ENABLED).asBoolean());
+ }
+
+ if (portNode.has(REMOVED)) {
+ builder.isRemoved(portNode.path(REMOVED).asBoolean());
+ }
+
+ if (portNode.has(TYPE)) {
+ builder.type(Port.Type.valueOf(portNode.path(TYPE).asText().toUpperCase()));
+ }
+
+ if (portNode.has(SPEED)) {
+ builder.portSpeed(portNode.path(SPEED).asLong());
+ }
+
+ if (portNode.has(ANNOTATIONS)) {
+ DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder();
+ Iterator<Map.Entry<String, JsonNode>> annotationsIt = portNode.get(ANNOTATIONS).fields();
+ while (annotationsIt.hasNext()) {
+ Map.Entry<String, JsonNode> entry = annotationsIt.next();
+ annotationsBuilder.set(entry.getKey(), entry.getValue().asText());
+ }
+ builder.annotations(annotationsBuilder.build());
+ }
+
+ portDescriptions.add(builder.build());
+ }
+
+ return portDescriptions.build();
+
+ } catch (IllegalArgumentException e) {
+ log.error(CONFIG_VALUE_ERROR, e);
+ return ImmutableList.of();
+ }
+ }
+
+ private PortNumber createPortNumber(long number, String name) {
+ if (name == null) {
+ return PortNumber.portNumber(number);
+ }
+ return PortNumber.portNumber(number, name);
+ }
+
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/statistic/PortStatisticsService.java b/core/api/src/main/java/org/onosproject/net/statistic/PortStatisticsService.java
new file mode 100644
index 0000000..4ed782b
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/statistic/PortStatisticsService.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.statistic;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.net.ConnectPoint;
+
+/**
+ * Service for obtaining statistic information about device ports.
+ */
+@Beta
+public interface PortStatisticsService {
+
+ /** Specifies the type of metric. */
+ enum MetricType {
+ /** Load is to be given in bytes/second. */
+ BYTES,
+
+ /** Load is to be given in packets/second. */
+ PACKETS
+ }
+
+ /**
+ * Obtain the egress load for the given port in terms of bytes per second.
+ *
+ * @param connectPoint the port to query
+ * @return egress traffic load
+ */
+ Load load(ConnectPoint connectPoint);
+
+ /**
+ * Obtain the egress load for the given port in terms of the specified metric.
+ *
+ * @param connectPoint the port to query
+ * @param metricType metric type
+ * @return egress traffic load
+ */
+ default Load load(ConnectPoint connectPoint, MetricType metricType) {
+ return load(connectPoint);
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/alarm/AlarmEntityIdTest.java b/core/api/src/test/java/org/onosproject/alarm/AlarmEntityIdTest.java
new file mode 100644
index 0000000..25a145b
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/alarm/AlarmEntityIdTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import com.google.common.testing.EqualsTester;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.alarm.AlarmEntityId.alarmEntityId;
+
+/**
+ * Test of the alarm source identifier.
+ *
+ */
+public class AlarmEntityIdTest {
+
+ /**
+ * Checks that the class is immutable.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(AlarmEntityId.class);
+ }
+
+ @Test
+ public void string() {
+ assertEquals("och:foo",
+ alarmEntityId("och:foo").toString());
+ }
+
+ @Test
+ public void basics() {
+ new EqualsTester()
+ .addEqualityGroup(
+ alarmEntityId("och:foo"),
+ alarmEntityId("och:foo"))
+ .addEqualityGroup(alarmEntityId("och:bar"))
+ .testEquals();
+
+ }
+
+ @Test
+ public void validSchemaPermitted() {
+ alarmEntityId("none:foo");
+ alarmEntityId("port:foo");
+ alarmEntityId("och:foo");
+ alarmEntityId("other:foo");
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void verifyUnexpectedSchemaRejected() {
+ alarmEntityId("junk:foo");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void verifyCorruptSchemaRejected() {
+ alarmEntityId("other:");
+ }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/alarm/AlarmIdTest.java b/core/api/src/test/java/org/onosproject/alarm/AlarmIdTest.java
new file mode 100644
index 0000000..a37c3cb
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/alarm/AlarmIdTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onosproject.net.DeviceId;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * This class tests the immutability, equality, and non-equality of {@link AlarmId}.
+ */
+public class AlarmIdTest {
+
+ private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar");
+ private static final String UNIQUE_ID_1 = "unique_id_1";
+ private static final AlarmId ID_A = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+
+ private static final String UNIQUE_ID_2 = "unique_id_2";
+
+ private static final String UNIQUE_ID_3 = "unique_id_3";
+ private static final AlarmId ID_Z = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_3);
+
+ private static final String ID_STRING = "foo:bar:unique_id_3";
+
+ /**
+ * Tests the immutability of {@link AlarmId}.
+ */
+ @Test
+ public void intentIdFollowsGuidelineForImmutableObject() {
+ assertThatClassIsImmutable(AlarmId.class);
+ }
+
+ /**
+ * Tests equality of {@link AlarmId}.
+ */
+ @Test
+ public void testEquality() {
+ final AlarmId id1 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+ final AlarmId id2 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+
+ assertThat(id1, is(id2));
+ }
+
+ /**
+ * Tests non-equality of {@link AlarmId}.
+ */
+ @Test
+ public void testNonEquality() {
+ final AlarmId id1 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+ final AlarmId id2 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_2);
+
+ assertThat(id1, is(not(id2)));
+ }
+
+ @Test
+ public void valueOf() {
+ final AlarmId id = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+ assertEquals("incorrect valueOf", id, ID_A);
+ }
+
+ /**
+ * Tests the equals(), hashCode() and toString() methods.
+ */
+ @Test
+ public void testEquals() {
+ final AlarmId id1 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+ final AlarmId sameAsId1 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+ final AlarmId id2 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_2);
+
+ new EqualsTester()
+ .addEqualityGroup(id1, sameAsId1)
+ .addEqualityGroup(id2)
+ .testEquals();
+ }
+
+ /**
+ * Tests construction of an AlarmId object.
+ */
+ @Test
+ public void testConstruction() {
+ final AlarmId id1 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_3);
+ assertEquals(id1.toString(), ID_Z.toString());
+
+ final AlarmId idString = AlarmId.alarmId(ID_STRING);
+ assertEquals(id1, idString);
+
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/alarm/AlarmProviderRegistryAdapter.java b/core/api/src/test/java/org/onosproject/alarm/AlarmProviderRegistryAdapter.java
new file mode 100644
index 0000000..f4075e5
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/alarm/AlarmProviderRegistryAdapter.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.alarm;
+
+import org.onosproject.net.provider.ProviderId;
+
+import java.util.Set;
+
+/**
+ * Adapter for Alarm Provider Registry.
+ */
+public class AlarmProviderRegistryAdapter implements AlarmProviderRegistry {
+
+ @Override
+ public AlarmProviderService register(AlarmProvider provider) {
+ return null;
+ }
+
+ @Override
+ public void unregister(AlarmProvider provider) {
+
+ }
+
+ @Override
+ public Set<ProviderId> getProviders() {
+ return null;
+ }
+}
diff --git a/core/api/src/test/java/org/onosproject/alarm/DefaultAlarmTest.java b/core/api/src/test/java/org/onosproject/alarm/DefaultAlarmTest.java
new file mode 100644
index 0000000..6818ef9
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/alarm/DefaultAlarmTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.alarm;
+
+import org.junit.Test;
+import org.onosproject.net.DeviceId;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+public class DefaultAlarmTest {
+
+ private static final AlarmEntityId ALARM_ENTITY_ID = AlarmEntityId.alarmEntityId("port:bar");
+ private static final DeviceId DEVICE_ID = DeviceId.deviceId("foo:bar");
+ private static final String UNIQUE_ID_1 = "unique_id_1";
+ private static final AlarmId ALARM_ID = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_1);
+ private static final String UNIQUE_ID_2 = "unique_id_1";
+ private static final AlarmId ALARM_ID_2 = AlarmId.alarmId(DEVICE_ID, UNIQUE_ID_2);
+
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultAlarm.class);
+ }
+
+ /**
+ * Checks the construction of a DefaultAlarm object.
+ */
+ @Test
+ public void testConstruction() {
+ final DefaultAlarm a = generate();
+ assertThat(a, is(notNullValue()));
+ final DefaultAlarm b = new DefaultAlarm.Builder(a).build();
+ assertEquals(a, b);
+ }
+
+ @Test
+ public void testEquals() {
+ final DefaultAlarm a = new DefaultAlarm.Builder(ALARM_ID_2,
+ DeviceId.NONE, "desc", Alarm.SeverityLevel.MINOR, 3).build();
+ final DefaultAlarm b = new DefaultAlarm.Builder(ALARM_ID,
+ DeviceId.NONE, "desc", Alarm.SeverityLevel.MINOR, a.timeRaised() + 1)
+ .withTimeUpdated(a.timeUpdated() + 1).build();
+ assertEquals("id or timeRaised or timeUpdated may differ", a, b);
+
+ assertNotEquals(a, new DefaultAlarm.Builder(a).withAcknowledged(!a.acknowledged()).build());
+ assertNotEquals(a, new DefaultAlarm.Builder(a).withManuallyClearable(!a.manuallyClearable()).build());
+ assertNotEquals(a, new DefaultAlarm.Builder(a).withServiceAffecting(!a.serviceAffecting()).build());
+ assertNotEquals(a, new DefaultAlarm.Builder(a).withAssignedUser("Changed" + a.assignedUser()).build());
+
+ }
+
+ @Test
+ public void testClear() {
+ final DefaultAlarm active = generate();
+ final DefaultAlarm cleared = new DefaultAlarm.Builder(active).clear().build();
+ assertNotEquals(active, cleared);
+ assertThat(cleared.timeRaised(), is(active.timeRaised()));
+ assertThat(cleared.severity(), is(Alarm.SeverityLevel.CLEARED));
+ assertThat(cleared.timeUpdated(), greaterThan(active.timeUpdated()));
+ assertNotNull(cleared.timeCleared());
+
+ }
+
+ @Test
+ public void testId() {
+ final DefaultAlarm a = generate();
+ final DefaultAlarm b = new DefaultAlarm.Builder(a).build();
+
+ assertEquals("id ignored in equals", a, b);
+ assertEquals(ALARM_ID, a.id());
+ assertEquals(ALARM_ID, b.id());
+ assertEquals(ALARM_ENTITY_ID, b.source());
+
+ }
+
+ private static DefaultAlarm generate() {
+ return new DefaultAlarm.Builder(ALARM_ID,
+ DeviceId.NONE, "desc", Alarm.SeverityLevel.MINOR, 3).forSource(ALARM_ENTITY_ID).build();
+ }
+}
diff --git a/core/common/BUILD b/core/common/BUILD
index be7fd44..9abdc58 100644
--- a/core/common/BUILD
+++ b/core/common/BUILD
@@ -1,6 +1,4 @@
-COMPILE_DEPS = CORE_DEPS + JACKSON + METRICS + [
- "//incubator/api:onos-incubator-api",
-]
+COMPILE_DEPS = CORE_DEPS + JACKSON + METRICS
TEST_DEPS = TEST + ["//core/api:onos-api-tests"]
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
index 07f44c8..a6bb8bf 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
@@ -27,22 +27,7 @@
import org.onosproject.codec.JsonCodec;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
-import org.onosproject.incubator.net.dpi.DpiStatInfo;
-import org.onosproject.incubator.net.dpi.DpiStatInfoCodec;
-import org.onosproject.incubator.net.dpi.DpiStatistics;
-import org.onosproject.incubator.net.dpi.DpiStatisticsCodec;
-import org.onosproject.incubator.net.dpi.FlowStatInfo;
-import org.onosproject.incubator.net.dpi.FlowStatInfoCodec;
-import org.onosproject.incubator.net.dpi.ProtocolStatInfo;
-import org.onosproject.incubator.net.dpi.ProtocolStatInfoCodec;
-import org.onosproject.incubator.net.dpi.TrafficStatInfo;
-import org.onosproject.incubator.net.dpi.TrafficStatInfoCodec;
-import org.onosproject.incubator.net.virtual.TenantId;
-import org.onosproject.incubator.net.virtual.VirtualDevice;
-import org.onosproject.incubator.net.virtual.VirtualHost;
-import org.onosproject.incubator.net.virtual.VirtualLink;
-import org.onosproject.incubator.net.virtual.VirtualNetwork;
-import org.onosproject.incubator.net.virtual.VirtualPort;
+import org.onosproject.net.TenantId;
import org.onosproject.mastership.MastershipTerm;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
@@ -164,19 +149,9 @@
registerCodec(DeviceKey.class, new DeviceKeyCodec());
registerCodec(Region.class, new RegionCodec());
registerCodec(TenantId.class, new TenantIdCodec());
- registerCodec(VirtualNetwork.class, new VirtualNetworkCodec());
- registerCodec(VirtualDevice.class, new VirtualDeviceCodec());
- registerCodec(VirtualPort.class, new VirtualPortCodec());
- registerCodec(VirtualLink.class, new VirtualLinkCodec());
- registerCodec(VirtualHost.class, new VirtualHostCodec());
registerCodec(MastershipTerm.class, new MastershipTermCodec());
registerCodec(MastershipRole.class, new MastershipRoleCodec());
registerCodec(RoleInfo.class, new RoleInfoCodec());
- registerCodec(DpiStatistics.class, new DpiStatisticsCodec());
- registerCodec(DpiStatInfo.class, new DpiStatInfoCodec());
- registerCodec(TrafficStatInfo.class, new TrafficStatInfoCodec());
- registerCodec(ProtocolStatInfo.class, new ProtocolStatInfoCodec());
- registerCodec(FlowStatInfo.class, new FlowStatInfoCodec());
registerCodec(FilteredConnectPoint.class, new FilteredConnectPointCodec());
registerCodec(TransportEndpointDescription.class, new TransportEndpointDescriptionCodec());
registerCodec(PacketRequest.class, new PacketRequestCodec());
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/TenantIdCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/TenantIdCodec.java
index a73daa2..3111c6b 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/TenantIdCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/TenantIdCodec.java
@@ -18,7 +18,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.TenantId;
+import org.onosproject.net.TenantId;
import static com.google.common.base.Preconditions.checkNotNull;
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java
deleted file mode 100644
index 79053ec..0000000
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualDeviceCodec.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.codec.impl;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.DefaultVirtualDevice;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualDevice;
-import org.onosproject.net.DeviceId;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.nullIsIllegal;
-
-/**
- * Codec for the VirtualDevice class.
- */
-public class VirtualDeviceCodec extends JsonCodec<VirtualDevice> {
-
- // JSON field names
- private static final String ID = "deviceId";
- private static final String NETWORK_ID = "networkId";
-
- private static final String NULL_OBJECT_MSG = "VirtualDevice cannot be null";
- private static final String MISSING_MEMBER_MSG = " member is required in VirtualDevice";
-
- @Override
- public ObjectNode encode(VirtualDevice vDev, CodecContext context) {
- checkNotNull(vDev, NULL_OBJECT_MSG);
-
- ObjectNode result = context.mapper().createObjectNode()
- .put(NETWORK_ID, vDev.networkId().toString())
- .put(ID, vDev.id().toString());
-
- return result;
- }
-
- @Override
- public VirtualDevice decode(ObjectNode json, CodecContext context) {
- if (json == null || !json.isObject()) {
- return null;
- }
-
- DeviceId dId = DeviceId.deviceId(extractMember(ID, json));
- NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
- return new DefaultVirtualDevice(nId, dId);
- }
-
- /**
- * Extract member from JSON ObjectNode.
- *
- * @param key key for which value is needed
- * @param json JSON ObjectNode
- * @return member value
- */
- private String extractMember(String key, ObjectNode json) {
- return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
- }
-}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualHostCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualHostCodec.java
deleted file mode 100644
index 0a6ee8c..0000000
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualHostCodec.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.codec.impl;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.MacAddress;
-import org.onlab.packet.VlanId;
-import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.DefaultVirtualHost;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualHost;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.HostId;
-import org.onosproject.net.HostLocation;
-import org.onosproject.net.PortNumber;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.nullIsIllegal;
-
-/**
- * Codec for the VirtualHost class.
- */
-public class VirtualHostCodec extends JsonCodec<VirtualHost> {
-
- // JSON field names
- static final String NETWORK_ID = "networkId";
- static final String HOST_ID = "id";
- static final String MAC_ADDRESS = "mac";
- static final String VLAN = "vlan";
- static final String IP_ADDRESSES = "ipAddresses";
- static final String HOST_LOCATION = "locations";
-
- private static final String NULL_OBJECT_MSG = "VirtualHost cannot be null";
- private static final String MISSING_MEMBER_MSG = " member is required in VirtualHost";
-
- @Override
- public ObjectNode encode(VirtualHost vHost, CodecContext context) {
- checkNotNull(vHost, NULL_OBJECT_MSG);
-
- final JsonCodec<HostLocation> locationCodec =
- context.codec(HostLocation.class);
- final ObjectNode result = context.mapper().createObjectNode()
- .put(NETWORK_ID, vHost.networkId().toString())
- .put(HOST_ID, vHost.id().toString())
- .put(MAC_ADDRESS, vHost.mac().toString())
- .put(VLAN, vHost.vlan().toString());
-
- final ArrayNode jsonIpAddresses = result.putArray(IP_ADDRESSES);
- for (final IpAddress ipAddress : vHost.ipAddresses()) {
- jsonIpAddresses.add(ipAddress.toString());
- }
- result.set(IP_ADDRESSES, jsonIpAddresses);
-
- final ArrayNode jsonLocations = result.putArray("locations");
- for (final HostLocation location : vHost.locations()) {
- jsonLocations.add(locationCodec.encode(location, context));
- }
- result.set("locations", jsonLocations);
-
- return result;
- }
-
- @Override
- public VirtualHost decode(ObjectNode json, CodecContext context) {
- if (json == null || !json.isObject()) {
- return null;
- }
-
- NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
- MacAddress mac = MacAddress.valueOf(json.get("mac").asText());
- VlanId vlanId = VlanId.vlanId((short) json.get("vlan").asInt(VlanId.UNTAGGED));
-
- Set<HostLocation> locations = new HashSet<>();
- JsonNode locationNodes = json.get("locations");
- locationNodes.forEach(locationNode -> {
- PortNumber portNumber = PortNumber.portNumber(locationNode.get("port").asText());
- DeviceId deviceId = DeviceId.deviceId(locationNode.get("elementId").asText());
- locations.add(new HostLocation(deviceId, portNumber, 0));
- });
-
- HostId id = HostId.hostId(mac, vlanId);
-
- Iterator<JsonNode> ipStrings = json.get("ipAddresses").elements();
- Set<IpAddress> ips = new HashSet<>();
- while (ipStrings.hasNext()) {
- ips.add(IpAddress.valueOf(ipStrings.next().asText()));
- }
-
- return new DefaultVirtualHost(nId, id, mac, vlanId, locations, ips);
- }
-
- /**
- * Extract member from JSON ObjectNode.
- *
- * @param key key for which value is needed
- * @param json JSON ObjectNode
- * @return member value
- */
- private String extractMember(String key, ObjectNode json) {
- return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
- }
-}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java
deleted file mode 100644
index 106a1b0..0000000
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualLinkCodec.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.codec.impl;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.DefaultVirtualLink;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualLink;
-import org.onosproject.net.Link;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.nullIsIllegal;
-
-/**
- * Codec for the VirtualLink class.
- */
-public class VirtualLinkCodec extends JsonCodec<VirtualLink> {
-
- // JSON field names
- private static final String NETWORK_ID = "networkId";
-
- private static final String NULL_OBJECT_MSG = "VirtualLink cannot be null";
- private static final String MISSING_MEMBER_MSG = " member is required in VirtualLink";
-
- @Override
- public ObjectNode encode(VirtualLink vLink, CodecContext context) {
- checkNotNull(vLink, NULL_OBJECT_MSG);
-
- ObjectNode result = context.mapper().createObjectNode()
- .put(NETWORK_ID, vLink.networkId().toString());
- JsonCodec<Link> codec = context.codec(Link.class);
- ObjectNode linkResult = codec.encode(vLink, context);
- result.setAll(linkResult);
- return result;
- }
-
- @Override
- public VirtualLink decode(ObjectNode json, CodecContext context) {
- if (json == null || !json.isObject()) {
- return null;
- }
- JsonCodec<Link> codec = context.codec(Link.class);
- Link link = codec.decode(json, context);
- NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
- return DefaultVirtualLink.builder()
- .networkId(nId)
- .src(link.src())
- .dst(link.dst())
- .build();
- }
-
- /**
- * Extract member from JSON ObjectNode.
- *
- * @param key key for which value is needed
- * @param json JSON ObjectNode
- * @return member value
- */
- private String extractMember(String key, ObjectNode json) {
- return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
- }
-}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualNetworkCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualNetworkCodec.java
deleted file mode 100644
index 156649a..0000000
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualNetworkCodec.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.codec.impl;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.TenantId;
-import org.onosproject.incubator.net.virtual.VirtualNetwork;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.nullIsIllegal;
-
-/**
- * Codec for the VirtualNetwork class.
- */
-public class VirtualNetworkCodec extends JsonCodec<VirtualNetwork> {
-
- // JSON field names
- private static final String NETWORK_ID = "networkId";
- private static final String TENANT_ID = "tenantId";
-
- private static final String NULL_OBJECT_MSG = "VirtualNetwork cannot be null";
- private static final String MISSING_MEMBER_MSG = " member is required in VirtualNetwork";
-
- @Override
- public ObjectNode encode(VirtualNetwork vnet, CodecContext context) {
- checkNotNull(vnet, NULL_OBJECT_MSG);
-
- ObjectNode result = context.mapper().createObjectNode()
- .put(NETWORK_ID, vnet.id().toString())
- .put(TENANT_ID, vnet.tenantId().toString());
-
- return result;
- }
-
- @Override
- public VirtualNetwork decode(ObjectNode json, CodecContext context) {
- if (json == null || !json.isObject()) {
- return null;
- }
-
- NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
- TenantId tId = TenantId.tenantId(extractMember(TENANT_ID, json));
- return new DefaultVirtualNetwork(nId, tId);
- }
-
- private String extractMember(String key, ObjectNode json) {
- return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
- }
-}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/VirtualPortCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/VirtualPortCodec.java
deleted file mode 100644
index 24a5d08..0000000
--- a/core/common/src/main/java/org/onosproject/codec/impl/VirtualPortCodec.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.codec.impl;
-
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.onosproject.codec.CodecContext;
-import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.DefaultVirtualPort;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualDevice;
-import org.onosproject.incubator.net.virtual.VirtualNetworkService;
-import org.onosproject.incubator.net.virtual.VirtualPort;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.PortNumber;
-
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.util.Tools.nullIsIllegal;
-
-/**
- * Codec for the VirtualPort class.
- */
-public class VirtualPortCodec extends JsonCodec<VirtualPort> {
-
- // JSON field names
- private static final String NETWORK_ID = "networkId";
- private static final String DEVICE_ID = "deviceId";
- private static final String PORT_NUM = "portNum";
- private static final String PHYS_DEVICE_ID = "physDeviceId";
- private static final String PHYS_PORT_NUM = "physPortNum";
-
- private static final String NULL_OBJECT_MSG = "VirtualPort cannot be null";
- private static final String MISSING_MEMBER_MSG = " member is required in VirtualPort";
- private static final String INVALID_VIRTUAL_DEVICE = " is not a valid VirtualDevice";
-
- @Override
- public ObjectNode encode(VirtualPort vPort, CodecContext context) {
- checkNotNull(vPort, NULL_OBJECT_MSG);
-
- ObjectNode result = context.mapper().createObjectNode()
- .put(NETWORK_ID, vPort.networkId().toString())
- .put(DEVICE_ID, vPort.element().id().toString())
- .put(PORT_NUM, vPort.number().toString())
- .put(PHYS_DEVICE_ID, vPort.realizedBy().deviceId().toString())
- .put(PHYS_PORT_NUM, vPort.realizedBy().port().toString());
-
- return result;
- }
-
- @Override
- public VirtualPort decode(ObjectNode json, CodecContext context) {
- if (json == null || !json.isObject()) {
- return null;
- }
-
- NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
- DeviceId dId = DeviceId.deviceId(extractMember(DEVICE_ID, json));
-
- VirtualNetworkService vnetService = context.getService(VirtualNetworkService.class);
- Set<VirtualDevice> vDevs = vnetService.getVirtualDevices(nId);
- VirtualDevice vDev = vDevs.stream()
- .filter(virtualDevice -> virtualDevice.id().equals(dId))
- .findFirst().orElse(null);
- nullIsIllegal(vDev, dId.toString() + INVALID_VIRTUAL_DEVICE);
-
- PortNumber portNum = PortNumber.portNumber(extractMember(PORT_NUM, json));
- DeviceId physDId = DeviceId.deviceId(extractMember(PHYS_DEVICE_ID, json));
- PortNumber physPortNum = PortNumber.portNumber(extractMember(PHYS_PORT_NUM, json));
-
- ConnectPoint realizedBy = new ConnectPoint(physDId, physPortNum);
- return new DefaultVirtualPort(nId, vDev, portNum, realizedBy);
- }
-
- private String extractMember(String key, ObjectNode json) {
- return nullIsIllegal(json.get(key), key + MISSING_MEMBER_MSG).asText();
- }
-}
diff --git a/core/common/src/main/java/org/onosproject/utils/Comparators.java b/core/common/src/main/java/org/onosproject/utils/Comparators.java
index 20a4497..1610648 100644
--- a/core/common/src/main/java/org/onosproject/utils/Comparators.java
+++ b/core/common/src/main/java/org/onosproject/utils/Comparators.java
@@ -20,10 +20,7 @@
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.intf.Interface;
-import org.onosproject.incubator.net.virtual.TenantId;
-import org.onosproject.incubator.net.virtual.VirtualDevice;
-import org.onosproject.incubator.net.virtual.VirtualNetwork;
-import org.onosproject.incubator.net.virtual.VirtualPort;
+import org.onosproject.net.TenantId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Element;
import org.onosproject.net.ElementId;
@@ -121,15 +118,4 @@
public static final Comparator<TenantId> TENANT_ID_COMPARATOR =
(t1, t2) -> t1.id().compareTo(t2.id());
- public static final Comparator<VirtualNetwork> VIRTUAL_NETWORK_COMPARATOR =
- (v1, v2) -> {
- int compareId = v1.tenantId().toString().compareTo(v2.tenantId().toString());
- return (compareId != 0) ? compareId : Long.signum(v1.id().id() - v2.id().id());
- };
-
- public static final Comparator<VirtualDevice> VIRTUAL_DEVICE_COMPARATOR =
- (v1, v2) -> v1.id().toString().compareTo(v2.id().toString());
-
- public static final Comparator<VirtualPort> VIRTUAL_PORT_COMPARATOR =
- (v1, v2) -> v1.number().toString().compareTo(v2.number().toString());
}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/VirtualHostCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/VirtualHostCodecTest.java
deleted file mode 100644
index 9cc26d4..0000000
--- a/core/common/src/test/java/org/onosproject/codec/impl/VirtualHostCodecTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.codec.impl;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Set;
-import java.util.stream.IntStream;
-
-import org.junit.Test;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.MacAddress;
-import org.onlab.packet.VlanId;
-import org.onosproject.codec.JsonCodec;
-import org.onosproject.incubator.net.virtual.DefaultVirtualHost;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualHost;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.HostId;
-import org.onosproject.net.HostLocation;
-import org.onosproject.net.NetTestTools;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.collect.ImmutableSet;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.isOneOf;
-import static org.hamcrest.Matchers.notNullValue;
-
-/**
- * Tests VirtualHostCodec class.
- */
-
-public class VirtualHostCodecTest {
-
- private static final String TEST_IP1 = "1.1.1.1";
- private static final String TEST_IP2 = "2.2.2.2";
- private static final String TEST_HOST_ID = "12:34:56:78:90:11/1";
- private static final String TEST_MAC_ADDRESS = "11:11:22:22:33:33";
- private static final long TEST_NETWORK_ID = 44L;
- private static final short TEST_VLAN_ID = (short) 12;
- private static final ConnectPoint CONNECT_POINT =
- NetTestTools.connectPoint("d1", 1);
-
- @Test
- public void testEncode() {
- MockCodecContext context = new MockCodecContext();
- NetworkId networkId = NetworkId.networkId(TEST_NETWORK_ID);
- HostId id = NetTestTools.hid(TEST_HOST_ID);
- MacAddress mac = MacAddress.valueOf(TEST_MAC_ADDRESS);
- VlanId vlan = VlanId.vlanId(TEST_VLAN_ID);
- HostLocation location =
- new HostLocation(CONNECT_POINT, 0L);
- Set<IpAddress> ips = ImmutableSet.of(IpAddress.valueOf(TEST_IP1),
- IpAddress.valueOf(TEST_IP2));
- VirtualHost host =
- new DefaultVirtualHost(networkId, id, mac, vlan, location, ips);
- JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
- ObjectNode node = codec.encode(host, context);
-
- assertThat(node.get(VirtualHostCodec.NETWORK_ID).asLong(),
- is(TEST_NETWORK_ID));
- assertThat(node.get(VirtualHostCodec.HOST_ID).asText(),
- is(TEST_HOST_ID));
- assertThat(node.get(VirtualHostCodec.MAC_ADDRESS).asText(),
- is(TEST_MAC_ADDRESS));
- assertThat(node.get(VirtualHostCodec.VLAN).asInt(),
- is((int) TEST_VLAN_ID));
- assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("elementId").asText(),
- is(location.deviceId().toString()));
- assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("port").asLong(),
- is(location.port().toLong()));
-
- JsonNode jsonIps = node.get(VirtualHostCodec.IP_ADDRESSES);
- assertThat(jsonIps, notNullValue());
- assertThat(jsonIps.isArray(), is(true));
- assertThat(jsonIps.size(), is(ips.size()));
-
- IntStream.of(0, 1).forEach(index ->
- assertThat(jsonIps.get(index).asText(),
- isOneOf(TEST_IP1, TEST_IP2)));
- }
-
- @Test
- public void testDecode() throws IOException {
- MockCodecContext context = new MockCodecContext();
- InputStream jsonStream =
- VirtualHostCodecTest.class.getResourceAsStream("VirtualHost.json");
- JsonNode json = context.mapper().readTree(jsonStream);
- assertThat(json, notNullValue());
- JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
- VirtualHost virtualHost = codec.decode((ObjectNode) json, context);
- assertThat(virtualHost, notNullValue());
-
- assertThat(virtualHost.networkId().id(),
- is(TEST_NETWORK_ID));
- assertThat(virtualHost.id().toString(),
- is(NetTestTools.hid(TEST_MAC_ADDRESS + "/12").toString()));
- assertThat(virtualHost.mac().toString(),
- is(TEST_MAC_ADDRESS));
- assertThat(virtualHost.vlan().id(),
- is((short) TEST_VLAN_ID));
- assertThat(virtualHost.location().deviceId(),
- is(CONNECT_POINT.deviceId()));
- assertThat(virtualHost.location().port().toLong(),
- is(CONNECT_POINT.port().toLong()));
-
-
- assertThat(virtualHost.ipAddresses().contains(IpAddress.valueOf(TEST_IP1)),
- is(true));
- assertThat(virtualHost.ipAddresses().contains(IpAddress.valueOf(TEST_IP2)),
- is(true));
- }
-}
diff --git a/core/common/src/test/java/org/onosproject/utils/ComparatorsTest.java b/core/common/src/test/java/org/onosproject/utils/ComparatorsTest.java
index d616e71..36d291e 100644
--- a/core/common/src/test/java/org/onosproject/utils/ComparatorsTest.java
+++ b/core/common/src/test/java/org/onosproject/utils/ComparatorsTest.java
@@ -52,9 +52,6 @@
import static org.onosproject.utils.Comparators.PORT_COMPARATOR;
import static org.onosproject.utils.Comparators.REGION_COMPARATOR;
import static org.onosproject.utils.Comparators.TENANT_ID_COMPARATOR;
-import static org.onosproject.utils.Comparators.VIRTUAL_DEVICE_COMPARATOR;
-import static org.onosproject.utils.Comparators.VIRTUAL_NETWORK_COMPARATOR;
-import static org.onosproject.utils.Comparators.VIRTUAL_PORT_COMPARATOR;
import java.util.Optional;
@@ -70,14 +67,7 @@
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.GroupId;
import org.onosproject.net.intf.Interface;
-import org.onosproject.incubator.net.virtual.DefaultVirtualDevice;
-import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork;
-import org.onosproject.incubator.net.virtual.DefaultVirtualPort;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.TenantId;
-import org.onosproject.incubator.net.virtual.VirtualDevice;
-import org.onosproject.incubator.net.virtual.VirtualNetwork;
-import org.onosproject.incubator.net.virtual.VirtualPort;
+import org.onosproject.net.TenantId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
@@ -117,12 +107,8 @@
public class ComparatorsTest {
- private static final ProviderId PID = new ProviderId("of", "foo");
- private static final DeviceId DID = deviceId("of:foo");
private static final String MFR = "whitebox";
- private static final String HW = "1.1.x";
private static final String HW1 = "2.2.x";
- private static final String SW = "3.9.1";
private static final String SW1 = "4.0.0";
private static final String SN = "43311-12345";
private static final ChassisId CID = new ChassisId();
@@ -346,41 +332,6 @@
return TenantId.tenantId(id);
}
- @Test
- public void testVirtualNetworkComparator() {
- assertNotEquals(0, VIRTUAL_NETWORK_COMPARATOR.compare(network(10, "tenantID"), network(10, "tenantID1")));
- assertNotEquals(0, VIRTUAL_NETWORK_COMPARATOR.compare(network(10, "tenantID"), network(15, "tenantID1")));
- assertNotEquals(0, VIRTUAL_NETWORK_COMPARATOR.compare(network(15, "tenantID1"), network(10, "tenantID1")));
- assertNotEquals(0, VIRTUAL_NETWORK_COMPARATOR.compare(network(15, "tenantID"), network(10, "tenantID1")));
- }
-
- private VirtualNetwork network(int networkID, String tenantID) {
- return new DefaultVirtualNetwork(NetworkId.networkId(networkID), TenantId.tenantId(tenantID));
- }
-
- @Test
- public void testVirtualDeviceComparator() {
- assertEquals(0, VIRTUAL_DEVICE_COMPARATOR.compare(vd(0, "of:foo"), vd(0, "of:foo")));
- assertEquals(0, VIRTUAL_DEVICE_COMPARATOR.compare(vd(3, "of:foo"), vd(0, "of:foo")));
- assertNotEquals(0, VIRTUAL_DEVICE_COMPARATOR.compare(vd(0, "of:bar"), vd(0, "of:foo")));
- assertNotEquals(0, VIRTUAL_DEVICE_COMPARATOR.compare(vd(3, "of:bar"), vd(0, "of:foo")));
- }
-
- private VirtualDevice vd(int netID, String devID) {
- return new DefaultVirtualDevice(NetworkId.networkId(netID), DeviceId.deviceId(devID));
- }
-
- @Test
- public void testVirtualPortComparator() {
- assertEquals(0, VIRTUAL_PORT_COMPARATOR.compare(vPort(2), vPort(2)));
- assertEquals(4, VIRTUAL_PORT_COMPARATOR.compare(vPort(900), vPort(5)));
- assertEquals(-8, VIRTUAL_PORT_COMPARATOR.compare(vPort(0), vPort(8)));
- }
-
- private VirtualPort vPort(int portNumber) {
- return new DefaultVirtualPort(NetworkId.networkId(20), new DefaultDevice(PID, DID, null, MFR, HW, SW, SN, CID),
- PortNumber.portNumber(portNumber), new ConnectPoint(DID, PortNumber.portNumber(900)));
- }
}
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/VirtualHost.json b/core/common/src/test/resources/org/onosproject/codec/impl/VirtualHost.json
deleted file mode 100644
index 818ce0b..0000000
--- a/core/common/src/test/resources/org/onosproject/codec/impl/VirtualHost.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "networkId": "44",
- "mac": "11:11:22:22:33:33",
- "vlan": "12",
- "ipAddresses": [
- "1.1.1.1",
- "2.2.2.2"
- ],
- "locations": [
- {
- "elementId": "of:d1",
- "port": "1"
- }
- ]
-}
diff --git a/core/net/BUILD b/core/net/BUILD
index 571c45a..fc6c46d 100644
--- a/core/net/BUILD
+++ b/core/net/BUILD
@@ -1,9 +1,6 @@
COMPILE_DEPS = CORE_DEPS + JACKSON + METRICS + KRYO + [
"//core/common:onos-core-common",
- "//incubator/api:onos-incubator-api",
"//utils/rest:onlab-rest",
- "//incubator/net:onos-incubator-net",
- "//incubator/store:onos-incubator-store",
"//core/store/serializers:onos-core-serializers",
"//core/store/primitives:onos-core-primitives",
"@org_osgi_service_cm//jar",
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java b/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
index f5791de..a5d06a8 100644
--- a/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
@@ -17,7 +17,7 @@
import com.google.common.collect.ImmutableSet;
import org.onosproject.core.CoreService;
-import org.onosproject.incubator.net.config.basics.PortDescriptionsConfig;
+import org.onosproject.net.config.basics.PortDescriptionsConfig;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.HostId;
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
index 4caf74e..98880db 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
@@ -23,7 +23,7 @@
import org.onlab.util.Tools;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
-import org.onosproject.incubator.net.config.basics.PortDescriptionsConfig;
+import org.onosproject.net.config.basics.PortDescriptionsConfig;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipService;
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompiler.java
deleted file mode 100644
index 3222714..0000000
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompiler.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.net.intent.impl.compiler;
-
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.onlab.osgi.DefaultServiceDirectory;
-import org.onlab.osgi.ServiceDirectory;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.incubator.net.tunnel.TunnelId;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualNetworkIntent;
-import org.onosproject.incubator.net.virtual.VirtualNetworkService;
-import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
-import org.onosproject.incubator.net.virtual.VirtualPort;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.FilteredConnectPoint;
-import org.onosproject.net.Link;
-import org.onosproject.net.Path;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentCompilationException;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.PointToPointIntent;
-import org.onosproject.net.topology.TopologyService;
-import org.slf4j.Logger;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * An intent compiler for {@link org.onosproject.incubator.net.virtual.VirtualNetworkIntent}.
- */
-@Component(immediate = true)
-public class VirtualNetworkIntentCompiler
- extends ConnectivityIntentCompiler<VirtualNetworkIntent> {
-
- private final Logger log = getLogger(getClass());
-
- private static final String NETWORK_ID = "networkId=";
- protected static final String KEY_FORMAT = "{" + NETWORK_ID + "%s, src=%s, dst=%s}";
-
- protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected VirtualNetworkService manager;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected IntentService intentService;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY)
- protected VirtualNetworkStore store;
-
-
- @Activate
- public void activate() {
- intentManager.registerCompiler(VirtualNetworkIntent.class, this);
- }
-
- @Deactivate
- public void deactivate() {
- intentManager.unregisterCompiler(VirtualNetworkIntent.class);
- }
-
- @Override
- public List<Intent> compile(VirtualNetworkIntent intent, List<Intent> installable) {
-
- log.debug("Compiling intent: " + intent);
- List<Intent> intents = new ArrayList<>();
- Optional<Path> path = getPaths(intent).stream()
- .findFirst();
- if (path != null && path.isPresent()) {
- List<Link> links = path.get().links();
-
- // First create an intent between the intent ingress CP and the first link source CP,
- // only if the two CPs are not the same.
- Link firstLink = links.get(0);
- if (!intent.ingressPoint().equals(firstLink.src())) {
- intents.add(createPtPtIntent(intent, intent.ingressPoint(), firstLink.src()));
- }
-
- // Next create an intent between the intent egress CP and the last link destination CP,
- // only if the two CPs are not the same.
- Link lastLink = links.get(links.size() - 1);
- if (!intent.egressPoint().equals(lastLink.dst())) {
- intents.add(createPtPtIntent(intent, lastLink.dst(), intent.egressPoint()));
- }
-
- // Now loop through all of the virtual links in the path and create an intent.
- // An intent is also created connecting two virtual links.
- final int[] index = {0};
- links.forEach(link -> {
- intents.add(createPtPtIntent(intent, link.src(), link.dst()));
- if (index[0] > 0) {
- Link previousLink = links.get(index[0] - 1);
- intents.add(createPtPtIntent(intent, previousLink.dst(), link.src()));
- }
- index[0]++;
- });
- } else {
- throw new IntentCompilationException("Unable to find a path for intent " + intent);
- }
-
- return intents;
- }
-
- /**
- * Returns the paths for the virtual network intent.
- *
- * @param intent virtual network intent
- * @return set of paths
- */
- private Set<Path> getPaths(VirtualNetworkIntent intent) {
-
- TopologyService topologyService = manager.get(intent.networkId(), TopologyService.class);
- if (topologyService == null) {
- throw new IntentCompilationException("topologyService is null");
- }
- return topologyService.getPaths(topologyService.currentTopology(),
- intent.ingressPoint().deviceId(), intent.egressPoint().deviceId());
- }
-
- /**
- * Encodes the key using the network identifier, application identifier, source and destination
- * connect points.
- *
- * @param networkId virtual network identifier
- * @param applicationId application identifier
- * @param src source connect point
- * @param dst destination connect point
- * @return encoded key
- */
-
- private static Key encodeKey(NetworkId networkId, ApplicationId applicationId, ConnectPoint src, ConnectPoint dst) {
- String key = String.format(KEY_FORMAT, networkId, src, dst);
- return Key.of(key, applicationId);
- }
-
- /**
- * Creates a point-to-point intent using the virtual network intent between the source and destination
- * connect point.
- *
- * @param intent virtual network intent
- * @param src source connect point
- * @param dst destination connect point
- * @return point to point intent
- */
- private Intent createPtPtIntent(VirtualNetworkIntent intent, ConnectPoint src, ConnectPoint dst) {
- ConnectPoint ingressPoint = mapVirtualToPhysicalPort(intent.networkId(), src);
- ConnectPoint egressPoint = mapVirtualToPhysicalPort(intent.networkId(), dst);
- Key intentKey = encodeKey(intent.networkId(), intent.appId(), ingressPoint, egressPoint);
-
- // TODO Currently there can only be one intent between the ingress and egress across
- // all virtual networks. We may want to support multiple intents between the same src/dst pairs.
- PointToPointIntent physicalIntent = PointToPointIntent.builder()
- .key(intentKey)
- .appId(intent.appId())
- .filteredIngressPoint(new FilteredConnectPoint(ingressPoint))
- .filteredEgressPoint(new FilteredConnectPoint(egressPoint))
- .constraints(intent.constraints())
- .selector(intent.selector())
- .treatment(intent.treatment())
- .resourceGroup(intent.resourceGroup())
- .build();
- log.debug("Submitting physical intent: " + physicalIntent);
- intentService.submit(physicalIntent);
-
- // Store the physical intent against this virtual intent.
- store.addTunnelId(intent, TunnelId.valueOf(physicalIntent.key().toString()));
-
- return physicalIntent;
- }
-
- /**
- * Maps the virtual connect point to a physical connect point.
- *
- * @param networkId virtual network identifier
- * @param virtualCp virtual connect point
- * @return physical connect point
- */
- private ConnectPoint mapVirtualToPhysicalPort(NetworkId networkId, ConnectPoint virtualCp) {
- Set<VirtualPort> ports = manager.getVirtualPorts(networkId, virtualCp.deviceId());
- for (VirtualPort port : ports) {
- if (port.element().id().equals(virtualCp.elementId()) &&
- port.number().equals(virtualCp.port())) {
- return new ConnectPoint(port.realizedBy().deviceId(), port.realizedBy().port());
- }
- }
- return null;
- }
-}
-
diff --git a/core/net/src/main/java/org/onosproject/net/statistic/impl/PortStatisticsManager.java b/core/net/src/main/java/org/onosproject/net/statistic/impl/PortStatisticsManager.java
new file mode 100644
index 0000000..da41750
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/statistic/impl/PortStatisticsManager.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.statistic.impl;
+
+import com.google.common.collect.Maps;
+import org.onosproject.net.statistic.PortStatisticsService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortStatistics;
+import org.onosproject.net.statistic.DefaultLoad;
+import org.onosproject.net.statistic.Load;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
+import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED;
+import static org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Implementation of the port statistics service.
+ */
+@Component(immediate = true, service = PortStatisticsService.class)
+public class PortStatisticsManager implements PortStatisticsService {
+
+ private final Logger log = getLogger(getClass());
+
+ private static final long POLL_FREQUENCY = 10_000; // milliseconds
+ private static final long STALE_LIMIT = (long) (1.5 * POLL_FREQUENCY);
+ private static final int SECOND = 1_000; // milliseconds
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected DeviceService deviceService;
+
+ private final DeviceListener deviceListener = new InternalDeviceListener();
+
+ private Map<ConnectPoint, DataPoint> current = Maps.newConcurrentMap();
+ private Map<ConnectPoint, DataPoint> previous = Maps.newConcurrentMap();
+
+ @Activate
+ public void activate() {
+ deviceService.addListener(deviceListener);
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ deviceService.removeListener(deviceListener);
+ log.info("Stopped");
+ }
+
+ @Override
+ public Load load(ConnectPoint connectPoint) {
+ return load(connectPoint, MetricType.BYTES);
+ }
+
+ @Override
+ public Load load(ConnectPoint connectPoint, MetricType metricType) {
+ DataPoint c = current.get(connectPoint);
+ DataPoint p = previous.get(connectPoint);
+ long now = System.currentTimeMillis();
+
+ if (c != null && p != null && (now - c.time < STALE_LIMIT)) {
+ if (c.time > p.time + SECOND) {
+ long cve = getEgressValue(c.stats, metricType);
+ long cvi = getIngressValue(c.stats, metricType);
+ long pve = getEgressValue(p.stats, metricType);
+ long pvi = getIngressValue(p.stats, metricType);
+ //Use max of either Tx or Rx load as the total load of a port
+ Load load = null;
+ if (cve >= pve) {
+ load = new DefaultLoad(cve, pve, (int) (c.time - p.time) / SECOND);
+ }
+ if (cvi >= pvi) {
+ Load rcvLoad = new DefaultLoad(cvi, pvi, (int) (c.time - p.time) / SECOND);
+ load = ((load == null) || (rcvLoad.rate() > load.rate())) ? rcvLoad : load;
+ }
+ return load;
+ }
+ }
+ return null;
+ }
+
+ private long getEgressValue(PortStatistics stats, MetricType metricType) {
+ return metricType == MetricType.BYTES ? stats.bytesSent() : stats.packetsSent();
+ }
+
+ private long getIngressValue(PortStatistics stats, MetricType metricType) {
+ return metricType == MetricType.BYTES ? stats.bytesReceived() : stats.packetsReceived();
+ }
+
+ // Monitors port stats update messages.
+ private class InternalDeviceListener implements DeviceListener {
+ @Override
+ public void event(DeviceEvent event) {
+ DeviceEvent.Type type = event.type();
+ DeviceId deviceId = event.subject().id();
+ if (type == PORT_STATS_UPDATED) {
+ // Update port load
+ updateDeviceData(deviceId);
+
+ } else if (type == DEVICE_REMOVED ||
+ (type == DEVICE_AVAILABILITY_CHANGED &&
+ !deviceService.isAvailable(deviceId))) {
+ // Clean-up all port loads
+ pruneDeviceData(deviceId);
+ }
+ }
+ }
+
+ // Updates the port stats for the specified device
+ private void updateDeviceData(DeviceId deviceId) {
+ deviceService.getPortStatistics(deviceId)
+ .forEach(stats -> updatePortData(deviceId, stats));
+ }
+
+ // Updates the port stats for the specified port
+ private void updatePortData(DeviceId deviceId, PortStatistics stats) {
+ ConnectPoint cp = new ConnectPoint(deviceId, portNumber(stats.port()));
+ DataPoint c = current.get(cp);
+
+ // Create a new data point and make it the current one
+ current.put(cp, new DataPoint(stats));
+
+ // If we have a current data point, demote it to previous
+ if (c != null) {
+ previous.put(cp, c);
+ }
+ }
+
+ // Cleans all port loads for the specified device
+ private void pruneDeviceData(DeviceId deviceId) {
+ pruneMap(current, deviceId);
+ pruneMap(previous, deviceId);
+ }
+
+ private void pruneMap(Map<ConnectPoint, DataPoint> map, DeviceId deviceId) {
+ map.keySet().stream().filter(cp -> deviceId.equals(cp.deviceId()))
+ .collect(Collectors.toSet()).forEach(map::remove);
+ }
+
+ // Auxiliary data point to track when we receive different samples.
+ private class DataPoint {
+ long time;
+ PortStatistics stats;
+
+ DataPoint(PortStatistics stats) {
+ time = System.currentTimeMillis();
+ this.stats = stats;
+ }
+ }
+
+}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java
deleted file mode 100644
index 0af5742..0000000
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/VirtualNetworkIntentCompilerTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.net.intent.impl.compiler;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onlab.osgi.ServiceDirectory;
-import org.onlab.osgi.TestServiceDirectory;
-import org.onosproject.TestApplicationId;
-import org.onosproject.common.event.impl.TestEventDispatcher;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.core.CoreServiceAdapter;
-import org.onosproject.core.IdGenerator;
-import org.onosproject.incubator.net.virtual.TenantId;
-import org.onosproject.incubator.net.virtual.VirtualDevice;
-import org.onosproject.incubator.net.virtual.VirtualLink;
-import org.onosproject.incubator.net.virtual.VirtualNetwork;
-import org.onosproject.incubator.net.virtual.VirtualNetworkIntent;
-import org.onosproject.incubator.net.virtual.VirtualNetworkService;
-import org.onosproject.incubator.net.virtual.VirtualNetworkStore;
-import org.onosproject.incubator.net.virtual.impl.VirtualNetworkManager;
-import org.onosproject.incubator.store.virtual.impl.DistributedVirtualNetworkStore;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.DefaultPort;
-import org.onosproject.net.Link;
-import org.onosproject.net.NetTestTools;
-import org.onosproject.net.Port;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.TestDeviceParams;
-import org.onosproject.net.intent.FakeIntentManager;
-import org.onosproject.net.intent.Intent;
-import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.Key;
-import org.onosproject.net.intent.MockIdGenerator;
-import org.onosproject.net.intent.TestableIntentService;
-import org.onosproject.store.service.TestStorageService;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-import static org.junit.Assert.assertEquals;
-import static org.onlab.junit.TestUtils.TestUtilsException;
-import static org.onlab.junit.TestUtils.setField;
-
-/**
- * Junit tests for virtual network intent compiler.
- */
-public class VirtualNetworkIntentCompilerTest extends TestDeviceParams {
-
- private CoreService coreService;
- private TestableIntentService intentService = new FakeIntentManager();
- private IntentExtensionService intentExtensionService;
- private VirtualNetworkIntentCompiler compiler;
- private VirtualNetworkManager manager;
- private DistributedVirtualNetworkStore virtualNetworkManagerStore;
- private ServiceDirectory testDirectory;
-
- private final String tenantIdValue1 = "TENANT_ID1";
- private static final ApplicationId APP_ID =
- new TestApplicationId("test");
-
- private ConnectPoint cp1;
- private ConnectPoint cp2;
- private ConnectPoint cp3;
- private ConnectPoint cp4;
- private ConnectPoint cp5;
- private ConnectPoint cp6;
- private VirtualLink link1;
- private VirtualLink link2;
- private VirtualLink link3;
- private VirtualLink link4;
- private VirtualLink link5;
- private VirtualLink link6;
-
- @Before
- public void setUp() throws TestUtilsException {
- virtualNetworkManagerStore = new DistributedVirtualNetworkStore();
-
- coreService = new TestCoreService();
-
- MockIdGenerator.cleanBind();
-
- setField(virtualNetworkManagerStore, "coreService", coreService);
- setField(virtualNetworkManagerStore, "storageService", new TestStorageService());
- virtualNetworkManagerStore.activate();
-
- manager = new VirtualNetworkManager();
- manager.setStore(virtualNetworkManagerStore);
- setField(manager, "coreService", coreService);
- NetTestTools.injectEventDispatcher(manager, new TestEventDispatcher());
- manager.activate();
-
- // Register a compiler and an installer both setup for success.
- intentExtensionService = intentService;
-
- testDirectory = new TestServiceDirectory()
- .add(VirtualNetworkService.class, manager)
- .add(VirtualNetworkStore.class, virtualNetworkManagerStore)
- .add(IntentService.class, intentService);
- setField(manager, "serviceDirectory", testDirectory);
-
- compiler = new VirtualNetworkIntentCompiler();
- compiler.manager = manager;
- compiler.intentService = intentService;
- compiler.store = virtualNetworkManagerStore;
- compiler.intentManager = intentExtensionService;
- compiler.serviceDirectory = testDirectory;
- }
-
- @After
- public void tearDown() {
- manager.deactivate();
- MockIdGenerator.unbind();
- }
-
- /**
- * Method to create the virtual network for further testing.
- *
- * @return virtual network
- */
- private VirtualNetwork setupVirtualNetworkTopology() {
- manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
- VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
- VirtualDevice virtualDevice1 =
- manager.createVirtualDevice(virtualNetwork.id(), DID1);
- VirtualDevice virtualDevice2 =
- manager.createVirtualDevice(virtualNetwork.id(), DID2);
- VirtualDevice virtualDevice3 =
- manager.createVirtualDevice(virtualNetwork.id(), DID3);
- VirtualDevice virtualDevice4 =
- manager.createVirtualDevice(virtualNetwork.id(), DID4);
-
- Port port1 = new DefaultPort(virtualDevice1, PortNumber.portNumber(1), true);
- cp1 = new ConnectPoint(virtualDevice1.id(), port1.number());
- manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port1.number(), cp1);
-
- Port port2 = new DefaultPort(virtualDevice1, PortNumber.portNumber(2), true);
- cp2 = new ConnectPoint(virtualDevice1.id(), port2.number());
- manager.createVirtualPort(virtualNetwork.id(), virtualDevice1.id(), port2.number(), cp2);
-
- Port port3 = new DefaultPort(virtualDevice2, PortNumber.portNumber(3), true);
- cp3 = new ConnectPoint(virtualDevice2.id(), port3.number());
- manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port3.number(), cp3);
-
- Port port4 = new DefaultPort(virtualDevice2, PortNumber.portNumber(4), true);
- cp4 = new ConnectPoint(virtualDevice2.id(), port4.number());
- manager.createVirtualPort(virtualNetwork.id(), virtualDevice2.id(), port4.number(), cp4);
-
- Port port5 = new DefaultPort(virtualDevice3, PortNumber.portNumber(5), true);
- cp5 = new ConnectPoint(virtualDevice3.id(), port5.number());
- manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port5.number(), cp5);
-
- Port port6 = new DefaultPort(virtualDevice3, PortNumber.portNumber(6), true);
- cp6 = new ConnectPoint(virtualDevice3.id(), port6.number());
- manager.createVirtualPort(virtualNetwork.id(), virtualDevice3.id(), port6.number(), cp6);
-
- link1 = manager.createVirtualLink(virtualNetwork.id(), cp1, cp3);
- virtualNetworkManagerStore.updateLink(link1, link1.tunnelId(), Link.State.ACTIVE);
- link2 = manager.createVirtualLink(virtualNetwork.id(), cp3, cp1);
- virtualNetworkManagerStore.updateLink(link2, link2.tunnelId(), Link.State.ACTIVE);
- link3 = manager.createVirtualLink(virtualNetwork.id(), cp4, cp5);
- virtualNetworkManagerStore.updateLink(link3, link3.tunnelId(), Link.State.ACTIVE);
- link4 = manager.createVirtualLink(virtualNetwork.id(), cp5, cp4);
- virtualNetworkManagerStore.updateLink(link4, link4.tunnelId(), Link.State.ACTIVE);
-
- return virtualNetwork;
- }
-
- /**
- * Tests the virtual network intent compiler.
- */
- @Test
- public void testCompiler() {
- compiler.activate();
- VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
-
- Key intentKey = Key.of("test", APP_ID);
-
- VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder()
- .networkId(virtualNetwork.id())
- .key(intentKey)
- .appId(APP_ID)
- .ingressPoint(cp2)
- .egressPoint(cp6)
- .build();
-
- List<Intent> compiled = compiler.compile(virtualIntent, Collections.emptyList());
- assertEquals("The virtual intents size is not as expected.", 5, compiled.size());
-
- compiler.deactivate();
- }
-
-
- /**
- * Core service test class.
- */
- private class TestCoreService extends CoreServiceAdapter {
-
- @Override
- public IdGenerator getIdGenerator(String topic) {
- return new IdGenerator() {
- private AtomicLong counter = new AtomicLong(0);
-
- @Override
- public long getNewId() {
- return counter.getAndIncrement();
- }
- };
- }
- }
-
-}
diff --git a/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java b/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java
index ea21b9f..030b9e6 100644
--- a/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/meter/impl/MeterManagerTest.java
@@ -33,7 +33,6 @@
import org.onosproject.cluster.DefaultControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.common.event.impl.TestEventDispatcher;
-import org.onosproject.incubator.store.meter.impl.DistributedMeterStore;
import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DefaultAnnotations;
@@ -71,6 +70,7 @@
import org.onosproject.net.pi.PiPipeconfServiceAdapter;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
+import org.onosproject.store.meter.impl.DistributedMeterStore;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.TestStorageService;
diff --git a/core/protobuf/models/BUILD b/core/protobuf/models/BUILD
new file mode 100644
index 0000000..f04af82
--- /dev/null
+++ b/core/protobuf/models/BUILD
@@ -0,0 +1,7 @@
+COMPILE_DEPS = CORE_DEPS + [
+ "//core/protobuf/models/proto:onos-core-protobuf-models-proto",
+]
+
+osgi_jar_with_tests(
+ deps = COMPILE_DEPS,
+)
diff --git a/core/protobuf/models/proto/BUILD b/core/protobuf/models/proto/BUILD
new file mode 100644
index 0000000..7b426c5
--- /dev/null
+++ b/core/protobuf/models/proto/BUILD
@@ -0,0 +1,496 @@
+load("//tools/build/bazel:osgi_java_library.bzl", "osgi_proto_jar")
+
+PROTO_SOURCE_ROOT = "core/protobuf/models/proto"
+
+osgi_proto_jar(
+ name = "onos-core-protobuf-models-proto",
+ proto_libs = [
+ ":ApplicationsEnums_proto",
+ ":ConfigPropertyEnums_proto",
+ ":ConfigProperty_proto",
+ ":NodeId_proto",
+ ":RoleInfo_proto",
+ ":ApplicationId_proto",
+ ":ApplicationProto_proto",
+ ":Version_proto",
+ ":DeviceDescription_proto",
+ ":DeviceEnums_proto",
+ ":DeviceEvent_proto",
+ ":PortDescription_proto",
+ ":PortEnums_proto",
+ ":PortStatistics_proto",
+ ":Criterion_proto",
+ ":Instruction_proto",
+ ":Instructions_proto",
+ ":FlowEntryEnums_proto",
+ ":FlowEntry_proto",
+ ":FlowRuleEnums_proto",
+ ":FlowRule_proto",
+ ":TraficSelector_proto",
+ ":TrafficTreatment_proto",
+ ":HostDescription_proto",
+ ":HostEnums_proto",
+ ":HostEvent_proto",
+ ":LinkDescription_proto",
+ ":LinkEnums_proto",
+ ":LinkEvent_proto",
+ ":BandEnums_proto",
+ ":Band_proto",
+ ":MeterEnums_proto",
+ ":MeterEvent_proto",
+ ":Meter_proto",
+ ":MeterRequest_proto",
+ ":OutboundPacket_proto",
+ ":PacketEnums_proto",
+ ":PacketEvent_proto",
+ ":PacketProcessorEntry_proto",
+ ":PacketProcessor_proto",
+ ":PacketRequest_proto",
+ ":RegionEnums_proto",
+ ":ConnectPoint_proto",
+ ":Device_proto",
+ ":DisjointPath_proto",
+ ":HostId_proto",
+ ":HostLocation_proto",
+ ":Host_proto",
+ ":Link_proto",
+ ":MastershipRole_proto",
+ ":Path_proto",
+ ":Port_proto",
+ ":ProviderId_proto",
+ ":Region_proto",
+ ":Permission_proto",
+ ],
+)
+
+### app ###
+proto_library(
+ name = "ApplicationsEnums_proto",
+ srcs = ["app/ApplicationEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+### cfg ###
+proto_library(
+ name = "ConfigPropertyEnums_proto",
+ srcs = ["cfg/ConfigPropertyEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "ConfigProperty_proto",
+ srcs = ["cfg/ConfigPropertyProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":ConfigPropertyEnums_proto"],
+)
+
+### cluster ###
+proto_library(
+ name = "NodeId_proto",
+ srcs = ["cluster/NodeIdProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "RoleInfo_proto",
+ srcs = ["cluster/RoleInfoProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":NodeId_proto"],
+)
+
+### core ###
+
+proto_library(
+ name = "ApplicationId_proto",
+ srcs = ["core/ApplicationIdProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "ApplicationProto_proto",
+ srcs = ["core/ApplicationProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":ApplicationId_proto",
+ ":ApplicationsEnums_proto",
+ ":Permission_proto",
+ ":Version_proto",
+ ],
+)
+
+proto_library(
+ name = "Version_proto",
+ srcs = ["core/VersionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+### net ###
+
+### device ###
+proto_library(
+ name = "DeviceDescription_proto",
+ srcs = ["net/device/DeviceDescriptionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":DeviceEnums_proto"],
+)
+
+proto_library(
+ name = "DeviceEnums_proto",
+ srcs = ["net/device/DeviceEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "DeviceEvent_proto",
+ srcs = ["net/device/DeviceEventProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":DeviceEnums_proto",
+ ":Device_proto",
+ ":Port_proto",
+ ],
+)
+
+proto_library(
+ name = "PortDescription_proto",
+ srcs = ["net/device/PortDescriptionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":PortEnums_proto"],
+)
+
+proto_library(
+ name = "PortEnums_proto",
+ srcs = ["net/device/PortEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "PortStatistics_proto",
+ srcs = ["net/device/PortStatisticsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+### flow ###
+## criteria ##
+proto_library(
+ name = "Criterion_proto",
+ srcs = ["net/flow/criteria/CriterionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+## instrcutions ##
+proto_library(
+ name = "Instruction_proto",
+ srcs = ["net/flow/instructions/InstructionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "Instructions_proto",
+ srcs = ["net/flow/instructions/InstructionsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "FlowEntryEnums_proto",
+ srcs = ["net/flow/FlowEntryEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "FlowEntry_proto",
+ srcs = ["net/flow/FlowEntryProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = ["FlowEntryEnums_proto"],
+)
+
+proto_library(
+ name = "FlowRuleEnums_proto",
+ srcs = ["net/flow/FlowRuleEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "FlowRule_proto",
+ srcs = ["net/flow/FlowRuleProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":FlowRuleEnums_proto",
+ ":TrafficTreatment_proto",
+ ":TraficSelector_proto",
+ ],
+)
+
+proto_library(
+ name = "TraficSelector_proto",
+ srcs = ["net/flow/TrafficSelectorProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":Criterion_proto"],
+)
+
+proto_library(
+ name = "TrafficTreatment_proto",
+ srcs = ["net/flow/TrafficTreatmentProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ "Instruction_proto",
+ ":Instructions_proto",
+ ],
+)
+
+#### host ####
+
+proto_library(
+ name = "HostDescription_proto",
+ srcs = ["net/host/HostDescriptionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":HostLocation_proto"],
+)
+
+proto_library(
+ name = "HostEnums_proto",
+ srcs = ["net/host/HostEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "HostEvent_proto",
+ srcs = ["net/host/HostEventProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":HostEnums_proto",
+ ":Host_proto",
+ ],
+)
+
+#### link ####
+
+proto_library(
+ name = "LinkDescription_proto",
+ srcs = ["net/link/LinkDescriptionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":ConnectPoint_proto",
+ ":LinkEnums_proto",
+ ],
+)
+
+proto_library(
+ name = "LinkEnums_proto",
+ srcs = ["net/link/LinkEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "LinkEvent_proto",
+ srcs = ["net/link/LinkEventProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":LinkEnums_proto",
+ ":Link_proto",
+ ],
+)
+
+### meter ####
+
+proto_library(
+ name = "BandEnums_proto",
+ srcs = ["net/meter/BandEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "Band_proto",
+ srcs = ["net/meter/BandProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":BandEnums_proto"],
+)
+
+proto_library(
+ name = "MeterEnums_proto",
+ srcs = ["net/meter/MeterEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "MeterEvent_proto",
+ srcs = ["net/meter/MeterEventProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":MeterEnums_proto",
+ ":Meter_proto",
+ ],
+)
+
+proto_library(
+ name = "Meter_proto",
+ srcs = ["net/meter/MeterProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ "MeterEnums_proto",
+ ":ApplicationId_proto",
+ ":Band_proto",
+ ],
+)
+
+proto_library(
+ name = "MeterRequest_proto",
+ srcs = ["net/meter/MeterRequestProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":ApplicationId_proto",
+ ":Band_proto",
+ ":MeterEnums_proto",
+ ],
+)
+
+### packet ####
+
+proto_library(
+ name = "OutboundPacket_proto",
+ srcs = ["net/packet/OutboundPacketProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":TrafficTreatment_proto"],
+)
+
+proto_library(
+ name = "PacketEnums_proto",
+ srcs = ["net/packet/PacketEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "PacketEvent_proto",
+ srcs = ["net/packet/PacketEventProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":OutboundPacket_proto",
+ ":PacketEnums_proto",
+ ],
+)
+
+proto_library(
+ name = "PacketProcessorEntry_proto",
+ srcs = ["net/packet/PacketProcessorEntryProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":PacketProcessor_proto"],
+)
+
+proto_library(
+ name = "PacketProcessor_proto",
+ srcs = ["net/packet/PacketProcessorProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "PacketRequest_proto",
+ srcs = ["net/packet/PacketRequestProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":ApplicationId_proto",
+ ":NodeId_proto",
+ ":TraficSelector_proto",
+ ],
+)
+
+#### region ####
+
+proto_library(
+ name = "RegionEnums_proto",
+ srcs = ["net/region/RegionEnumsProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "ConnectPoint_proto",
+ srcs = ["net/ConnectPointProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "Device_proto",
+ srcs = ["net/DeviceProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":DeviceEnums_proto"],
+)
+
+proto_library(
+ name = "DisjointPath_proto",
+ srcs = ["net/DisjointPathProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":Path_proto"],
+)
+
+proto_library(
+ name = "HostId_proto",
+ srcs = ["net/HostIdProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "HostLocation_proto",
+ srcs = ["net/HostLocationProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":ConnectPoint_proto"],
+)
+
+proto_library(
+ name = "Host_proto",
+ srcs = ["net/HostProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":HostId_proto",
+ ":HostLocation_proto",
+ ":ProviderId_proto",
+ ],
+)
+
+proto_library(
+ name = "Link_proto",
+ srcs = ["net/LinkProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [
+ ":ConnectPoint_proto",
+ ":LinkEnums_proto",
+ ":ProviderId_proto",
+ ],
+)
+
+proto_library(
+ name = "MastershipRole_proto",
+ srcs = ["net/MastershipRoleProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "Path_proto",
+ srcs = ["net/PathProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":Link_proto"],
+)
+
+proto_library(
+ name = "Port_proto",
+ srcs = ["net/PortProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":PortEnums_proto"],
+)
+
+proto_library(
+ name = "ProviderId_proto",
+ srcs = ["net/ProviderIdProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
+
+proto_library(
+ name = "Region_proto",
+ srcs = ["net/RegionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+ deps = [":RegionEnums_proto"],
+)
+
+proto_library(
+ name = "Permission_proto",
+ srcs = ["security/PermissionProto.proto"],
+ proto_source_root = PROTO_SOURCE_ROOT,
+)
diff --git a/core/protobuf/models/proto/app/ApplicationEnumsProto.proto b/core/protobuf/models/proto/app/ApplicationEnumsProto.proto
new file mode 100644
index 0000000..2a1a912
--- /dev/null
+++ b/core/protobuf/models/proto/app/ApplicationEnumsProto.proto
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.app.models";
+
+package app;
+
+enum ApplicationStateProto {
+ // Indicates that application has been installed, but is not running.
+ INSTALLED = 0;
+ // Indicates that application is active.
+ ACTIVE = 1;
+}
+
+enum ApplicationRoleProto {
+ // Indicates that an application has an ADMIN role.
+ ADMIN = 0;
+ // Indicates that an application has a USER role.
+ USER = 1;
+ // Indicates that an application role has not been specified.
+ UNSPECIFIED = 2;
+
+ // More useful roles may be defined...
+}
diff --git a/core/protobuf/models/proto/cfg/ConfigPropertyEnumsProto.proto b/core/protobuf/models/proto/cfg/ConfigPropertyEnumsProto.proto
new file mode 100644
index 0000000..00204e7
--- /dev/null
+++ b/core/protobuf/models/proto/cfg/ConfigPropertyEnumsProto.proto
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.cfg.models";
+
+package cfg;
+
+enum ConfigPropertyTypeProto {
+ STRING = 0;
+ BYTE = 1;
+ INTEGER = 2;
+ LONG = 3;
+ FLOAT = 4;
+ DOUBLE = 5;
+ BOOLEAN = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/cfg/ConfigPropertyProto.proto b/core/protobuf/models/proto/cfg/ConfigPropertyProto.proto
new file mode 100644
index 0000000..d3ae6ac
--- /dev/null
+++ b/core/protobuf/models/proto/cfg/ConfigPropertyProto.proto
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.cfg.models";
+
+package cfg;
+
+import "cfg/ConfigPropertyEnumsProto.proto";
+
+// Corresponds to org.onosproject.cfg.ConfigProperty.
+message ConfigPropertyProto {
+ string name = 1;
+ cfg.ConfigPropertyTypeProto type = 2;
+ string value = 3;
+ string default_value = 4;
+ string description = 5;
+ bool is_set = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/cluster/NodeIdProto.proto b/core/protobuf/models/proto/cluster/NodeIdProto.proto
new file mode 100644
index 0000000..48d4494
--- /dev/null
+++ b/core/protobuf/models/proto/cluster/NodeIdProto.proto
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.cluster.models";
+
+package cluster;
+
+message NodeIdProto {
+ string node_id = 1;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/cluster/RoleInfoProto.proto b/core/protobuf/models/proto/cluster/RoleInfoProto.proto
new file mode 100644
index 0000000..1ede9ae
--- /dev/null
+++ b/core/protobuf/models/proto/cluster/RoleInfoProto.proto
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.cluster.models";
+
+import "cluster/NodeIdProto.proto";
+
+package cluster;
+
+message RoleInfoProto {
+ cluster.NodeIdProto master = 1;
+ repeated cluster.NodeIdProto backups = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/core/ApplicationIdProto.proto b/core/protobuf/models/proto/core/ApplicationIdProto.proto
new file mode 100644
index 0000000..59dacc8
--- /dev/null
+++ b/core/protobuf/models/proto/core/ApplicationIdProto.proto
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.core.models";
+
+package core;
+
+// Corresponds to org.onosproject.core.ApplicationId.
+message ApplicationIdProto {
+ uint32 id = 1;
+ string name = 2;
+}
diff --git a/core/protobuf/models/proto/core/ApplicationProto.proto b/core/protobuf/models/proto/core/ApplicationProto.proto
new file mode 100644
index 0000000..4601e3b
--- /dev/null
+++ b/core/protobuf/models/proto/core/ApplicationProto.proto
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.core.models";
+
+package core;
+
+import "core/ApplicationIdProto.proto";
+import "app/ApplicationEnumsProto.proto";
+import "security/PermissionProto.proto";
+import "core/VersionProto.proto";
+
+// Corresponds to org.onosproject.core.Application.
+message ApplicationProto {
+ core.ApplicationIdProto app_id = 1;
+ core.VersionProto version = 2;
+ string title = 3;
+ string description = 4;
+ string category = 5;
+ string url = 6;
+ string readme = 7;
+
+ // tag id 8 is reserved for app icon
+ reserved 8;
+
+ string origin = 9;
+ app.ApplicationRoleProto role = 10;
+ repeated security.PermissionProto permissions = 11;
+
+ // tag id 12 is reserved for features repo
+ // optional type will be added later
+ reserved 12;
+ repeated string features = 13;
+ repeated string required_apps = 14;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/core/VersionProto.proto b/core/protobuf/models/proto/core/VersionProto.proto
new file mode 100644
index 0000000..e1458a9
--- /dev/null
+++ b/core/protobuf/models/proto/core/VersionProto.proto
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.core.models";
+
+package core;
+
+// Corresponds to org.onosproject.core.
+message VersionProto {
+ int32 major = 1;
+ int32 minor = 2;
+ string patch = 3;
+ string build = 4;
+}
diff --git a/core/protobuf/models/proto/net/ConnectPointProto.proto b/core/protobuf/models/proto/net/ConnectPointProto.proto
new file mode 100644
index 0000000..9607b7e
--- /dev/null
+++ b/core/protobuf/models/proto/net/ConnectPointProto.proto
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+message ConnectPointProto {
+ oneof element_id {
+ // DeviceID as String DeviceId#toString
+ string device_id = 1;
+ string host_id = 3;
+ string ip_element_id = 4;
+ }
+ // PortNumber as String PortNumber#toString
+ string port_number = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/DeviceProto.proto b/core/protobuf/models/proto/net/DeviceProto.proto
new file mode 100644
index 0000000..9726d84
--- /dev/null
+++ b/core/protobuf/models/proto/net/DeviceProto.proto
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+import "net/device/DeviceEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.Device.
+message DeviceProto {
+ string device_id = 1;
+ net.device.DeviceTypeProto type = 2;
+ string manufacturer = 3;
+ string hw_version = 4;
+ string sw_version = 5;
+ string serial_number = 6;
+ string chassis_id = 7;
+ map<string, string> annotations = 8;
+}
diff --git a/core/protobuf/models/proto/net/DisjointPathProto.proto b/core/protobuf/models/proto/net/DisjointPathProto.proto
new file mode 100644
index 0000000..e80d4ec
--- /dev/null
+++ b/core/protobuf/models/proto/net/DisjointPathProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+import "net/PathProto.proto";
+
+// Corresponds to org.onosproject.net.DisjointPath.
+message DisjointPathProto {
+ net.PathProto primary = 1;
+ net.PathProto backup = 2;
+ map<string, string> annotations = 3;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/HostIdProto.proto b/core/protobuf/models/proto/net/HostIdProto.proto
new file mode 100644
index 0000000..a0aae4c
--- /dev/null
+++ b/core/protobuf/models/proto/net/HostIdProto.proto
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+// Corresponds to org.onosproject.net.HostId.
+message HostIdProto {
+ string mac = 1;
+ uint32 vlan_id = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/HostLocationProto.proto b/core/protobuf/models/proto/net/HostLocationProto.proto
new file mode 100644
index 0000000..9e44eba
--- /dev/null
+++ b/core/protobuf/models/proto/net/HostLocationProto.proto
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+import "net/ConnectPointProto.proto";
+
+package net;
+
+// Corresponds to org.onosproject.net.HostLocation.
+message HostLocationProto {
+ net.ConnectPointProto connect_point = 1;
+ uint64 time = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/HostProto.proto b/core/protobuf/models/proto/net/HostProto.proto
new file mode 100644
index 0000000..ba38fab
--- /dev/null
+++ b/core/protobuf/models/proto/net/HostProto.proto
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+import "net/HostIdProto.proto";
+import "net/HostLocationProto.proto";
+import "net/ProviderIdProto.proto";
+
+package net;
+
+// Corresponds to org.onosproject.net.Host.
+message HostProto {
+ net.HostIdProto host_id = 1;
+ uint32 vlan = 2;
+ net.HostLocationProto location = 3;
+ repeated string ip_addresses = 4;
+ bool configured = 5;
+ net.ProviderIdProto provider_id = 6;
+ map<string, string> annotations = 7;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/LinkProto.proto b/core/protobuf/models/proto/net/LinkProto.proto
new file mode 100644
index 0000000..e5ce70a
--- /dev/null
+++ b/core/protobuf/models/proto/net/LinkProto.proto
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+import "net/link/LinkEnumsProto.proto";
+import "net/ConnectPointProto.proto";
+import "net/ProviderIdProto.proto";
+
+// Corresponds to org.onosproject.net.Link.
+message LinkProto {
+ net.link.LinkStateProto state = 1;
+ net.ConnectPointProto src = 2;
+ net.ConnectPointProto dst = 3;
+ net.link.LinkTypeProto type = 4;
+ map<string, string> annotations = 5;
+ net.ProviderIdProto provider_id = 6;
+ bool isExpected = 7;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/MastershipRoleProto.proto b/core/protobuf/models/proto/net/MastershipRoleProto.proto
new file mode 100644
index 0000000..24508d5
--- /dev/null
+++ b/core/protobuf/models/proto/net/MastershipRoleProto.proto
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+enum MastershipRoleProto {
+ NONE = 0;
+ MASTER = 1;
+ STANDBY = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/PathProto.proto b/core/protobuf/models/proto/net/PathProto.proto
new file mode 100644
index 0000000..02343ae
--- /dev/null
+++ b/core/protobuf/models/proto/net/PathProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+import "net/LinkProto.proto";
+
+// Corresponds to org.onosproject.net.Path.
+message PathProto {
+ repeated net.LinkProto links = 1;
+ double weight = 2;
+ map<string, string> annotations = 3;
+}
diff --git a/core/protobuf/models/proto/net/PortProto.proto b/core/protobuf/models/proto/net/PortProto.proto
new file mode 100644
index 0000000..09282e3
--- /dev/null
+++ b/core/protobuf/models/proto/net/PortProto.proto
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+import "net/device/PortEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.Port.
+message PortProto {
+ string port_number = 1;
+ bool is_enabled = 2;
+ net.device.PortTypeProto type = 3;
+ int64 port_speed = 4;
+ map<string, string> annotations = 5;
+}
+
diff --git a/core/protobuf/models/proto/net/ProviderIdProto.proto b/core/protobuf/models/proto/net/ProviderIdProto.proto
new file mode 100644
index 0000000..9f4e4cf
--- /dev/null
+++ b/core/protobuf/models/proto/net/ProviderIdProto.proto
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+// Corresponds to org.onosproject.net.provider.ProviderId
+message ProviderIdProto {
+ string scheme = 1;
+ string id = 2;
+ bool ancillary = 3;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/RegionProto.proto b/core/protobuf/models/proto/net/RegionProto.proto
new file mode 100644
index 0000000..b760b6e
--- /dev/null
+++ b/core/protobuf/models/proto/net/RegionProto.proto
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.models";
+
+package net;
+
+import "net/region/RegionEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.Region.
+
+message RegionProto {
+ string region_id = 1;
+ net.region.RegionTypeProto type = 2;
+ string name = 3;
+
+ // List<Set<NodeId>> masters();
+ // Since masters is a list of set of NodeIds,
+ // the following message is required.
+ message NodeIdSet {
+ repeated string node_id = 1;
+ }
+
+ repeated NodeIdSet masters = 4;
+ map<string, string> annotations = 5;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/device/DeviceDescriptionProto.proto b/core/protobuf/models/proto/net/device/DeviceDescriptionProto.proto
new file mode 100644
index 0000000..d2eb2c7
--- /dev/null
+++ b/core/protobuf/models/proto/net/device/DeviceDescriptionProto.proto
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.device.models";
+
+package net.device;
+
+import "net/device/DeviceEnumsProto.proto";
+
+message DeviceDescriptionProto {
+ string device_uri = 1;
+ net.device.DeviceTypeProto type = 2;
+ string manufacturer = 3;
+ string hw_version = 4;
+ string sw_version = 5;
+ string serial_number = 6;
+ string chassis_id = 7;
+ map<string, string> annotations = 8;
+ bool is_default_available = 9;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/device/DeviceEnumsProto.proto b/core/protobuf/models/proto/net/device/DeviceEnumsProto.proto
new file mode 100644
index 0000000..e8713d3
--- /dev/null
+++ b/core/protobuf/models/proto/net/device/DeviceEnumsProto.proto
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.device.models";
+
+package net.device;
+
+enum DeviceTypeProto {
+ OTHER = 0;
+ SWITCH = 1;
+ ROUTER = 2;
+ ROADM = 3;
+ OTN = 4;
+ ROADM_OTN = 5;
+ FIREWALL = 6;
+ BALANCER = 7;
+ IPS = 8;
+ IDS = 9;
+ CONTROLLER = 10;
+ VIRTUAL_DEVICE = 11;
+ FIBER_SWITCH = 12;
+ MICROWAVE = 13;
+}
+
+enum DeviceEventTypeProto {
+ DEVICE_ADDED = 0;
+ DEVICE_UPDATED = 1;
+ DEVICE_REMOVED = 2;
+ DEVICE_SUSPENDED = 3;
+ DEVICE_AVAILABILITY_CHANGED = 4;
+ PORT_ADDED = 5;
+ PORT_UPDATED = 6;
+ PORT_REMOVED = 7;
+ PORT_STATS_UPDATED = 8;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/device/DeviceEventProto.proto b/core/protobuf/models/proto/net/device/DeviceEventProto.proto
new file mode 100644
index 0000000..f973bcc
--- /dev/null
+++ b/core/protobuf/models/proto/net/device/DeviceEventProto.proto
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.device.models";
+
+
+import "net/DeviceProto.proto";
+import "net/device/DeviceEnumsProto.proto";
+import "net/PortProto.proto";
+
+package net.device;
+
+// Corresponds to org.onosproject.net.device.DeviceEvent.
+message DeviceNotificationProto {
+ net.DeviceProto device = 1;
+ net.device.DeviceEventTypeProto device_event_type = 2;
+ net.PortProto port = 3;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/device/PortDescriptionProto.proto b/core/protobuf/models/proto/net/device/PortDescriptionProto.proto
new file mode 100644
index 0000000..52a6e23
--- /dev/null
+++ b/core/protobuf/models/proto/net/device/PortDescriptionProto.proto
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.device.models";
+
+package net.device;
+
+import "net/device/PortEnumsProto.proto";
+
+message PortDescriptionProto {
+ // PortNumber as String PortNumber#toString
+ string port_number = 1;
+ bool is_enabled = 2;
+ net.device.PortTypeProto type = 3;
+ int64 port_speed = 4;
+ map<string, string> annotations = 8;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/device/PortEnumsProto.proto b/core/protobuf/models/proto/net/device/PortEnumsProto.proto
new file mode 100644
index 0000000..28757fc
--- /dev/null
+++ b/core/protobuf/models/proto/net/device/PortEnumsProto.proto
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.device.models";
+
+package net.device;
+
+enum PortTypeProto {
+ // Signifies copper-based connectivity.
+ COPPER = 0;
+ // Signifies optical fiber-based connectivity.
+ FIBER = 1;
+ // Signifies optical fiber-based packet port.
+ PACKET = 2;
+ // Signifies optical fiber-based optical tributary port (called T-port).
+ //The signal from the client side will be formed into a ITU G.709 (OTN) frame.
+ ODUCLT = 3;
+ // Signifies optical fiber-based Line-side port (called L-port).
+ OCH = 4;
+ // Signifies optical fiber-based WDM port (called W-port).
+ //Optical Multiplexing Section (See ITU G.709).
+ OMS = 5;
+ // Signifies virtual port.
+ VIRTUAL_PORT = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/device/PortStatisticsProto.proto b/core/protobuf/models/proto/net/device/PortStatisticsProto.proto
new file mode 100644
index 0000000..af0b039
--- /dev/null
+++ b/core/protobuf/models/proto/net/device/PortStatisticsProto.proto
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.device.models";
+
+package net.device;
+
+message PortStatisticsProto {
+ int32 port = 1;
+ int64 packets_received = 2;
+ int64 packets_sent = 3;
+ int64 bytes_received = 4;
+ int64 bytes_sent = 5;
+ int64 packets_rx_dropped = 6;
+ int64 packets_tx_dropped = 7;
+ int64 packets_rx_errors = 8;
+ int64 packets_tx_errors = 9;
+ int64 duration_sec = 10;
+ int64 duration_nano = 11;
+ bool is_zero = 12;
+ // TODO add all other fields
+}
diff --git a/core/protobuf/models/proto/net/flow/FlowEntryEnumsProto.proto b/core/protobuf/models/proto/net/flow/FlowEntryEnumsProto.proto
new file mode 100644
index 0000000..2bb6768
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/FlowEntryEnumsProto.proto
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.models";
+
+package net.flow;
+
+// Corresponds to org.onosproject.net.flow.FlowEntry.
+enum FlowEntryStateProto {
+
+ // Indicates that this rule has been submitted for addition.
+ // Not necessarily in the flow table.
+ PENDING_ADD = 0;
+
+ // Rule has been added which means it is in the flow table.
+ ADDED = 1;
+
+ // Flow has been marked for removal, might still be in flow table.
+ PENDING_REMOVE = 2;
+
+ // Flow has been removed from flow table and can be purged.
+ REMOVED = 3;
+
+ // Indicates that the installation of this flow has failed.
+ FAILED = 4;
+}
+
+enum FlowLiveTypeProto {
+
+ // Indicates that this rule has been submitted for addition immediately.
+ // Not necessarily collecting flow stats.
+ IMMEDIATE = 0;
+
+ // Indicates that this rule has been submitted for a short time.
+ // Collecting flow stats every SHORT interval, defined by the implementation.
+ SHORT = 1;
+
+ // Indicates that this rule has been submitted for a mid time.
+ // Collecting flow stats every MID interval, defined by the implementation.
+ MID = 2;
+
+ // Indicates that this rule has been submitted for a long time.
+ // Collecting flow stats every LONG interval, defined by the implementation.
+ LONG = 3;
+
+ // Indicates that this rule has been submitted for UNKNOWN or ERROR.
+ // Not necessarily collecting flow stats.
+ UNKNOWN = 4;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/FlowEntryProto.proto b/core/protobuf/models/proto/net/flow/FlowEntryProto.proto
new file mode 100644
index 0000000..c28a624
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/FlowEntryProto.proto
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.models";
+
+package net.flow;
+
+import "net/flow/FlowEntryEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.flow.DefaultFlowEntry.
+message FlowEntryProto {
+ int64 life = 1;
+ int64 packets = 2;
+ int64 bytes = 3;
+ int64 last_seen = 4;
+ int32 err_type = 5;
+ int32 err_code = 6;
+
+ net.flow.FlowEntryStateProto state = 7;
+ net.flow.FlowLiveTypeProto live_type = 8;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/FlowRuleEnumsProto.proto b/core/protobuf/models/proto/net/flow/FlowRuleEnumsProto.proto
new file mode 100644
index 0000000..269f429
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/FlowRuleEnumsProto.proto
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.models";
+
+package net.flow;
+
+// Corresponds to org.onosproject.net.flow.FlowRule enums.
+enum FlowRemoveReasonProto {
+ IDLE_TIMEOUT = 0;
+ HARD_TIMEOUT = 1;
+ DELETE = 2;
+ GROUP_DELETE = 3;
+ METER_DELETE = 4;
+ EVICTION = 5;
+ NO_REASON = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/FlowRuleProto.proto b/core/protobuf/models/proto/net/flow/FlowRuleProto.proto
new file mode 100644
index 0000000..9bf615d
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/FlowRuleProto.proto
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.models";
+
+package net.flow;
+
+import "net/flow/TrafficSelectorProto.proto";
+import "net/flow/TrafficTreatmentProto.proto";
+import "net/flow/FlowRuleEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.flow.DefaultFlowRule.
+message FlowRuleProto {
+ int32 priority = 1;
+ int32 app_id = 2;
+ string device_id = 3;
+ int64 flow_id = 4;
+ int32 timeout = 5;
+ bool permanent = 6;
+ int32 table_id = 7;
+ string table_name = 8;
+
+ net.flow.TrafficSelectorProto selector = 9;
+ net.flow.TrafficTreatmentProto treatment = 10;
+ net.flow.FlowRemoveReasonProto reason = 11;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/TrafficSelectorProto.proto b/core/protobuf/models/proto/net/flow/TrafficSelectorProto.proto
new file mode 100644
index 0000000..74a5bce
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/TrafficSelectorProto.proto
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.models";
+
+package net.flow;
+
+import "net/flow/criteria/CriterionProto.proto";
+
+// Corresponds to org.onosproject.net.flow.TrafficSelector.
+message TrafficSelectorProto {
+ repeated net.flow.criteria.CriterionProto criterion = 1;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/TrafficTreatmentProto.proto b/core/protobuf/models/proto/net/flow/TrafficTreatmentProto.proto
new file mode 100644
index 0000000..428e218
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/TrafficTreatmentProto.proto
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.models";
+
+package net.flow;
+
+import "net/flow/instructions/InstructionsProto.proto";
+import "net/flow/instructions/InstructionProto.proto";
+
+// Corresponds to org.onosproject.net.flow.TrafficTreatment.
+message TrafficTreatmentProto {
+ repeated net.flow.instructions.InstructionProto deferred = 1;
+ repeated net.flow.instructions.InstructionProto immediate = 2;
+ repeated net.flow.instructions.InstructionProto all_instructions = 3;
+ net.flow.instructions.TableTypeTransitionProto table_transition = 4;
+ bool cleared_deferred = 5;
+ net.flow.instructions.MetadataInstructionProto write_metadata = 6;
+ net.flow.instructions.MetadataInstructionProto metered = 7;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/criteria/CriterionProto.proto b/core/protobuf/models/proto/net/flow/criteria/CriterionProto.proto
new file mode 100644
index 0000000..cc26526
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/criteria/CriterionProto.proto
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.criteria.models";
+
+package net.flow.criteria;
+
+enum TypeProto {
+ IN_PORT = 0;
+ ETH_DST = 1;
+ ETH_SRC = 2;
+ ETH_TYPE = 3;
+ IPV4_SRC = 4;
+ IPV4_DST = 5;
+ UDP_SRC = 6;
+ UDP_DST = 7;
+ TCP_SRC = 8;
+ TCP_DST = 9;
+ VLAN_VID = 10;
+ ARP_OP = 11;
+ ARP_SPA = 12;
+ ARP_TPA = 13;
+ ARP_SHA = 14;
+ ARP_THA = 15;
+ IP_PROTO = 16;
+ ETH_DST_MASKED = 17;
+ ETH_SRC_MASKED = 18;
+ VLAN_PCP = 19;
+ INNER_VLAN_VID = 20;
+ INNER_VLAN_PCP = 21;
+ IP_DSCP = 22;
+ IP_ECN = 23;
+ IN_PHY_PORT = 24;
+ METADATA = 25;
+ TCP_SRC_MASKED = 26;
+ TCP_DST_MASKED = 27;
+ UDP_SRC_MASKED = 28;
+ UDP_DST_MASKED = 29;
+ SCTP_SRC = 30;
+ SCTP_SRC_MASKED = 31;
+ SCTP_DST = 32;
+ SCTP_DST_MASKED = 33;
+ ICMPV4_TYPE = 34;
+ ICMPV4_CODE = 35;
+ IPV6_SRC = 36;
+ IPV6_DST = 37;
+ IPV6_FLABEL = 38;
+ ICMPV6_TYPE = 39;
+ ICMPV6_CODE = 40;
+ IPV6_ND_TARGET = 41;
+ IPV6_ND_SLL = 42;
+ IPV6_ND_TLL = 43;
+ MPLS_LABEL = 44;
+ MPLS_TC = 45;
+ MPLS_BOS = 46;
+ PBB_ISID = 47;
+ TUNNEL_ID = 48;
+ IPV6_EXTHDR =49;
+ UNASSIGNED_40 = 50;
+ PBB_UCA = 51;
+ TCP_FLAGS = 52;
+ ACTSET_OUTPUT = 53;
+ PACKET_TYPE = 54;
+ OCH_SIGID = 55;
+ OCH_SIGTYPE = 56;
+ ODU_SIGID = 57;
+ ODU_SIGTYPE = 58;
+ PROTOCOL_INDEPENDENT = 59;
+ EXTENSION = 60;
+ DUMMY = 61;
+}
+
+message CriterionProto {
+ TypeProto type = 1;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/instructions/InstructionProto.proto b/core/protobuf/models/proto/net/flow/instructions/InstructionProto.proto
new file mode 100644
index 0000000..472899f
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/instructions/InstructionProto.proto
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.instructions.models";
+
+package net.flow.instructions;
+
+enum TypeProto {
+ NOACTION = 0;
+ OUTPUT = 1;
+ GROUP = 2;
+ QUEUE = 3;
+ METER = 4;
+ L0MODIFICATION = 5;
+ L1MODIFICATION = 6;
+ L2MODIFICATION = 7;
+ L3MODIFICATION = 8;
+ L4MODIFICATION = 9;
+ TABLE = 10;
+ METADATA = 11;
+ PROTOCOL_INDEPENDENT = 12;
+ EXTENSION = 13;
+}
+
+message InstructionProto {
+ TypeProto type = 1;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/flow/instructions/InstructionsProto.proto b/core/protobuf/models/proto/net/flow/instructions/InstructionsProto.proto
new file mode 100644
index 0000000..7491623
--- /dev/null
+++ b/core/protobuf/models/proto/net/flow/instructions/InstructionsProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.flow.instructions.models";
+
+package net.flow.instructions;
+
+message TableTypeTransitionProto {
+ int32 table_id = 1;
+}
+
+message MetadataInstructionProto {
+ int64 meta_data = 1;
+ int64 meta_data_mask = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/host/HostDescriptionProto.proto b/core/protobuf/models/proto/net/host/HostDescriptionProto.proto
new file mode 100644
index 0000000..733fd8c
--- /dev/null
+++ b/core/protobuf/models/proto/net/host/HostDescriptionProto.proto
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.host.models";
+
+package net.host;
+
+import "net/HostLocationProto.proto";
+
+// Corresponds to org.onosproject.net.host.HostDescription.
+message HostDescription {
+ string hw_address = 1;
+ uint32 vlan = 2;
+ net.HostLocationProto location = 3;
+ repeated string ip_addresses = 4;
+ bool configured = 5;
+ map<string, string> annotations = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/host/HostEnumsProto.proto b/core/protobuf/models/proto/net/host/HostEnumsProto.proto
new file mode 100644
index 0000000..7d45f29
--- /dev/null
+++ b/core/protobuf/models/proto/net/host/HostEnumsProto.proto
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.host.models";
+
+package net.host;
+
+enum HostEventTypeProto {
+ HOST_ADDED = 0;
+ HOST_REMOVED = 1;
+ HOST_UPDATED = 2;
+ HOST_MOVED = 3;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/host/HostEventProto.proto b/core/protobuf/models/proto/net/host/HostEventProto.proto
new file mode 100644
index 0000000..c88dc20
--- /dev/null
+++ b/core/protobuf/models/proto/net/host/HostEventProto.proto
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.host.models";
+
+package net.host;
+
+import "net/HostProto.proto";
+import "net/host/HostEnumsProto.proto";
+
+
+// Corresponds to org.onosproject.net.device.HostEvent.
+message HostNotificationProto {
+ net.HostProto host = 1;
+ net.host.HostEventTypeProto hostEventType = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/link/LinkDescriptionProto.proto b/core/protobuf/models/proto/net/link/LinkDescriptionProto.proto
new file mode 100644
index 0000000..9519f3c
--- /dev/null
+++ b/core/protobuf/models/proto/net/link/LinkDescriptionProto.proto
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.link.models";
+
+package net.link;
+
+import "net/ConnectPointProto.proto";
+import "net/link/LinkEnumsProto.proto";
+
+message LinkDescriptionProto {
+ net.ConnectPointProto src = 1;
+ net.ConnectPointProto dst = 2;
+ net.link.LinkTypeProto type = 3;
+ map<string, string> annotations = 4;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/link/LinkEnumsProto.proto b/core/protobuf/models/proto/net/link/LinkEnumsProto.proto
new file mode 100644
index 0000000..ea76f9e
--- /dev/null
+++ b/core/protobuf/models/proto/net/link/LinkEnumsProto.proto
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.link.models";
+
+package net.link;
+
+enum LinkTypeProto {
+ // Signifies that this is a direct single-segment link.
+ DIRECT = 0;
+
+ // Signifies that this link is potentially comprised from multiple
+ // underlying segments or hops, and as such should be used to tag
+ // links traversing optical paths, tunnels or intervening 'dark'
+ // switches.
+ INDIRECT = 1;
+
+ // Signifies that this link is an edge, i.e. host link.
+ EDGE = 2;
+
+ // Signifies that this link represents a logical link backed by
+ // some form of a tunnel, e.g., GRE, MPLS, ODUk, OCH.
+ TUNNEL = 3;
+
+ // Signifies that this link is realized by fiber (either single channel or WDM).
+ OPTICAL = 4;
+
+ // Signifies that this link is a virtual link or a pseudo-wire.
+ VIRTUAL = 5;
+}
+
+enum LinkStateProto {
+ ACTIVE = 0;
+ INACTIVE = 1;
+}
+
+// Link Event Types
+enum LinkEventTypeProto {
+ LINK_ADDED = 0;
+ LINK_UPDATED = 1;
+ LINK_REMOVED = 2;
+}
diff --git a/core/protobuf/models/proto/net/link/LinkEventProto.proto b/core/protobuf/models/proto/net/link/LinkEventProto.proto
new file mode 100644
index 0000000..3772109
--- /dev/null
+++ b/core/protobuf/models/proto/net/link/LinkEventProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.link.models";
+
+package net.link;
+
+import "net/LinkProto.proto";
+import "net/link/LinkEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.link.LinkEvent.
+message LinkNotificationProto {
+ net.link.LinkEventTypeProto link_event_type = 1;
+ net.LinkProto link = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/meter/BandEnumsProto.proto b/core/protobuf/models/proto/net/meter/BandEnumsProto.proto
new file mode 100644
index 0000000..48dbe61
--- /dev/null
+++ b/core/protobuf/models/proto/net/meter/BandEnumsProto.proto
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.meter.models";
+
+package net.meter;
+
+/**
+* Specifies the type of band.
+*/
+enum BandTypeProto {
+ /**
+ * Simple rate limiter which drops packets
+ * when the rate is exceeded.
+ */
+ DROP = 0;
+
+ /**
+ * defines a simple DiffServ policer that remark
+ * the drop precedence of the DSCP field in the
+ * IP header of the packets that exceed the band
+ * rate value.
+ */
+ REMARK = 1;
+
+ /**
+ * defines an experimental meter band.
+ */
+ EXPERIMENTAL = 2;
+}
diff --git a/core/protobuf/models/proto/net/meter/BandProto.proto b/core/protobuf/models/proto/net/meter/BandProto.proto
new file mode 100644
index 0000000..4757c46
--- /dev/null
+++ b/core/protobuf/models/proto/net/meter/BandProto.proto
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.meter.models";
+
+package net.meter;
+
+import "net/meter/BandEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.meter.Band.
+message BandProto {
+ uint64 rate = 1;
+ uint64 burst = 2;
+ uint32 drop_precedence = 3;
+ BandTypeProto type = 4;
+ uint64 packets = 5;
+ uint64 bytes = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/meter/MeterEnumsProto.proto b/core/protobuf/models/proto/net/meter/MeterEnumsProto.proto
new file mode 100644
index 0000000..1b0bbf5
--- /dev/null
+++ b/core/protobuf/models/proto/net/meter/MeterEnumsProto.proto
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.meter.models";
+
+package net.meter;
+
+enum MeterUnitProto {
+ /**
+ * Packets per second.
+ */
+ PKTS_PER_SEC = 0;
+
+ /**
+ * Kilo bits per second.
+ */
+ KB_PER_SEC = 1;
+}
+
+enum MeterStateProto {
+ /**
+ * The meter is in the process of being added.
+ */
+ PENDING_ADD = 0;
+
+ /**
+ * THe meter has been added.
+ */
+ ADDED = 1;
+
+ /**
+ * The meter is in the process of being removed.
+ */
+ PENDING_REMOVE = 2;
+
+ /**
+ * The meter has been removed.
+ */
+ REMOVED = 3;
+}
+
+enum MeterRequestTypeProto {
+ ADD = 0;
+ MODIFY = 1;
+ REMOVE = 2;
+}
+
+enum MeterEventTypeProto {
+ /**
+ * A meter addition was requested.
+ */
+ METER_ADD_REQ = 0;
+
+ /**
+ * A meter removal was requested.
+ */
+ METER_REM_REQ = 1;
+
+ /**
+ * A meter was finally added to device.
+ */
+ METER_ADDED = 2;
+
+ /**
+ * A meter was finally removed from device.
+ */
+ METER_REMOVED = 3;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/meter/MeterEventProto.proto b/core/protobuf/models/proto/net/meter/MeterEventProto.proto
new file mode 100644
index 0000000..898692a
--- /dev/null
+++ b/core/protobuf/models/proto/net/meter/MeterEventProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.meter.models";
+
+package net.meter;
+
+import "net/meter/MeterEnumsProto.proto";
+import "net/meter/MeterProto.proto";
+
+// Corresponds to org.onosproject.net.meter.MeterEvent.
+message MeterNotificationProto {
+ MeterEventTypeProto type = 1;
+ MeterProto meter = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/meter/MeterProto.proto b/core/protobuf/models/proto/net/meter/MeterProto.proto
new file mode 100644
index 0000000..9478394
--- /dev/null
+++ b/core/protobuf/models/proto/net/meter/MeterProto.proto
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.meter.models";
+
+package net.meter;
+
+import "net/meter/BandProto.proto";
+import "net/meter/MeterEnumsProto.proto";
+import "core/ApplicationIdProto.proto";
+
+message MeterProto {
+ string device_id = 1;
+ uint64 meter_id = 2;
+ core.ApplicationIdProto application_id = 3;
+ MeterUnitProto unit = 4;
+ bool is_burst = 5;
+ repeated BandProto bands = 6;
+ MeterStateProto state = 7;
+ uint64 life = 8;
+ uint64 reference_count = 9;
+ uint64 packets_seen = 10;
+ uint64 bytes_seen = 11;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/meter/MeterRequestProto.proto b/core/protobuf/models/proto/net/meter/MeterRequestProto.proto
new file mode 100644
index 0000000..be60f11
--- /dev/null
+++ b/core/protobuf/models/proto/net/meter/MeterRequestProto.proto
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.meter.models";
+
+package net.meter;
+
+import "net/meter/BandProto.proto";
+import "net/meter/MeterEnumsProto.proto";
+import "core/ApplicationIdProto.proto";
+
+message MeterRequestProto {
+ string device_id = 1;
+ core.ApplicationIdProto application_id = 2;
+ MeterUnitProto unit = 3;
+ bool is_burst = 4;
+ repeated BandProto bands = 5;
+ MeterRequestTypeProto type = 6;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/packet/OutboundPacketProto.proto b/core/protobuf/models/proto/net/packet/OutboundPacketProto.proto
new file mode 100644
index 0000000..9d943e4
--- /dev/null
+++ b/core/protobuf/models/proto/net/packet/OutboundPacketProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.packet.models";
+
+package net.packet;
+
+import "net/flow/TrafficTreatmentProto.proto";
+
+// Corresponds to org.onosproject.net.packet.OutboundPacket.
+message OutboundPacketProto {
+ string device_id = 1;
+ net.flow.TrafficTreatmentProto treatment = 2;
+ bytes data = 3;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/packet/PacketEnumsProto.proto b/core/protobuf/models/proto/net/packet/PacketEnumsProto.proto
new file mode 100644
index 0000000..db6e5ca
--- /dev/null
+++ b/core/protobuf/models/proto/net/packet/PacketEnumsProto.proto
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.packet.models";
+
+package net.packet;
+
+enum PacketEventTypeProto {
+ EMIT = 0;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/packet/PacketEventProto.proto b/core/protobuf/models/proto/net/packet/PacketEventProto.proto
new file mode 100644
index 0000000..07d9580
--- /dev/null
+++ b/core/protobuf/models/proto/net/packet/PacketEventProto.proto
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.packet.models";
+
+package net.packet;
+
+import "net/packet/OutboundPacketProto.proto";
+import "net/packet/PacketEnumsProto.proto";
+
+// Corresponds to org.onosproject.net.packet.PacketEvent.
+message PacketNotificationProto {
+ net.packet.OutboundPacketProto outbound_packet = 1;
+ net.packet.PacketEventTypeProto packet_event_type = 2;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/packet/PacketProcessorEntryProto.proto b/core/protobuf/models/proto/net/packet/PacketProcessorEntryProto.proto
new file mode 100644
index 0000000..b0b90b2
--- /dev/null
+++ b/core/protobuf/models/proto/net/packet/PacketProcessorEntryProto.proto
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.packet.models";
+
+package net.packet;
+
+import "net/packet/PacketProcessorProto.proto";
+
+// Corresponds to org.onosproject.net.packet.PacketProcessorEntry.
+message PacketProcessorEntryProto {
+ net.packet.PacketProcessorProto packet_processor = 1;
+ int32 priority = 2;
+ int64 invocations = 3;
+ int64 total_nanos = 4;
+ int64 average_nanos = 5;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/packet/PacketProcessorProto.proto b/core/protobuf/models/proto/net/packet/PacketProcessorProto.proto
new file mode 100644
index 0000000..8a71674
--- /dev/null
+++ b/core/protobuf/models/proto/net/packet/PacketProcessorProto.proto
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.packet.models";
+
+package net.packet;
+
+// Corresponds to org.onosproject.net.packet.PacketProcessor.
+message PacketProcessorProto {
+ int32 priority = 1;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/packet/PacketRequestProto.proto b/core/protobuf/models/proto/net/packet/PacketRequestProto.proto
new file mode 100644
index 0000000..0b61a66
--- /dev/null
+++ b/core/protobuf/models/proto/net/packet/PacketRequestProto.proto
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.packet.models";
+
+package net.packet;
+
+import "net/flow/TrafficSelectorProto.proto";
+import "cluster/NodeIdProto.proto";
+import "core/ApplicationIdProto.proto";
+
+// Corresponds to org.onosproject.net.packet.PacketRequest.
+message PacketRequestProto {
+ net.flow.TrafficSelectorProto traffic_selector = 1;
+ int32 priority = 2;
+ core.ApplicationIdProto application_id = 3;
+ cluster.NodeIdProto node_id = 4;
+ string device_id = 5;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/net/region/RegionEnumsProto.proto b/core/protobuf/models/proto/net/region/RegionEnumsProto.proto
new file mode 100644
index 0000000..67bf53f
--- /dev/null
+++ b/core/protobuf/models/proto/net/region/RegionEnumsProto.proto
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.net.region.models";
+
+package net.region;
+
+enum RegionTypeProto {
+ /**
+ * Region represents an entire continent.
+ */
+ CONTINENT = 0;
+
+ /**
+ * Region represents an entire country.
+ */
+ COUNTRY = 1;
+
+ /**
+ * Region represents a metropolitan area.
+ */
+ METRO = 2;
+
+ /**
+ * Region represents a campus.
+ */
+ CAMPUS = 3;
+
+ /**
+ * Region represents a building.
+ */
+ BUILDING = 4;
+
+ /**
+ * Region represents a data center.
+ */
+ DATA_CENTER = 5;
+
+ /**
+ * Region represents a building floor.
+ */
+ FLOOR = 6;
+
+ /**
+ * Region represents a room.
+ */
+ ROOM = 7;
+
+ /**
+ * Region represents a rack.
+ */
+ RACK = 8;
+
+ /**
+ * Region represents a logical grouping.
+ */
+ LOGICAL_GROUP = 9;
+}
\ No newline at end of file
diff --git a/core/protobuf/models/proto/security/PermissionProto.proto b/core/protobuf/models/proto/security/PermissionProto.proto
new file mode 100644
index 0000000..e14af96
--- /dev/null
+++ b/core/protobuf/models/proto/security/PermissionProto.proto
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+syntax = "proto3";
+option java_package = "org.onosproject.grpc.security.models";
+
+package security;
+
+// Corresponds to org.onosproject.security.Permission.
+message PermissionProto {
+ string classname = 1;
+ string name = 2;
+ string actions = 3;
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/ConfigPropertyEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/ConfigPropertyEnumsProtoTranslator.java
new file mode 100644
index 0000000..d08e2fa
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/ConfigPropertyEnumsProtoTranslator.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.incubator.protobuf.models.cfg;
+
+import org.onosproject.cfg.ConfigProperty.Type;
+import org.onosproject.grpc.cfg.models.ConfigPropertyEnumsProto.ConfigPropertyTypeProto;
+
+/**
+ * gRPC ConfigProperty.Type message to equivalent ONOS enum conversion related utilities.
+ */
+public final class ConfigPropertyEnumsProtoTranslator {
+
+ /**
+ * Translates gRPC ConfigProperty type to {@link Type}.
+ *
+ * @param configPropertyTypeProto config Property proto type
+ * @return {@link Type}
+ */
+ public static Type translate(ConfigPropertyTypeProto configPropertyTypeProto) {
+
+ return Type.valueOf(configPropertyTypeProto.name());
+ }
+
+ /**
+ * Translates {@link Type} to gRPC ConfigProperty type.
+ *
+ * @param type config Property type
+ * @return gRPC ConfigProperty type
+ */
+ public static ConfigPropertyTypeProto translate(Type type) {
+
+ return ConfigPropertyTypeProto.valueOf(type.name());
+ }
+
+ // Utility class not intended for instantiation.
+ private ConfigPropertyEnumsProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/ConfigPropertyProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/ConfigPropertyProtoTranslator.java
new file mode 100644
index 0000000..ecf9baf
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/ConfigPropertyProtoTranslator.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.incubator.protobuf.models.cfg;
+
+import org.onosproject.cfg.ConfigProperty;
+import org.onosproject.grpc.cfg.models.ConfigPropertyProtoOuterClass.ConfigPropertyProto;
+
+/**
+ * gRPC ConfigPropertyProto message to equivalent ONOS ConfigProperty conversion related utilities.
+ */
+public final class ConfigPropertyProtoTranslator {
+
+ /**
+ * Translates gRPC ConfigProperty message to {@link ConfigProperty}.
+ *
+ * @param configPropertyProto gRPC message
+ * @return {@link ConfigProperty}
+ */
+ public static ConfigProperty translate(ConfigPropertyProto configPropertyProto) {
+
+ ConfigProperty configProperty = ConfigProperty.defineProperty(configPropertyProto.getName(),
+ ConfigPropertyEnumsProtoTranslator
+ .translate(configPropertyProto
+ .getType()),
+ configPropertyProto.getDefaultValue(),
+ configPropertyProto.getDescriptionBytes()
+ .toString());
+ return ConfigProperty.setProperty(configProperty, configPropertyProto.getValue());
+ }
+
+ /**
+ * Translates {@link ConfigProperty} to gRPC ConfigProperty message.
+ *
+ * @param configProperty config property
+ * @return gRPC ConfigProperty message
+ */
+ public static ConfigPropertyProto translate(ConfigProperty configProperty) {
+
+ if (configProperty != null) {
+ return ConfigPropertyProto.newBuilder()
+ .setName(configProperty.name())
+ .setType(ConfigPropertyEnumsProtoTranslator.translate(configProperty.type()))
+ .setDefaultValue(configProperty.defaultValue())
+ .setDescription(configProperty.description())
+ .setValue(configProperty.value())
+ .build();
+ }
+
+ return ConfigPropertyProto.getDefaultInstance();
+ }
+
+ // Utility class not intended for instantiation.
+ private ConfigPropertyProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/package-info.java
new file mode 100644
index 0000000..b0ea47d
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cfg/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS network models.
+ */
+package org.onosproject.incubator.protobuf.models.cfg;
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/NodeIdProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/NodeIdProtoTranslator.java
new file mode 100644
index 0000000..f41586d
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/NodeIdProtoTranslator.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.cluster;
+
+import org.onosproject.cluster.NodeId;
+import org.onosproject.grpc.net.cluster.models.NodeIdProtoOuterClass;
+
+/**
+ * gRPC NodeIdProto message to equivalent ONOS NodeId conversion related utilities.
+ */
+public final class NodeIdProtoTranslator {
+
+ /**
+ * Translates gRPC NodeId to {@link NodeId}.
+ *
+ * @param nodeId gRPC message
+ * @return {@link NodeId}
+ */
+ public static NodeId translate(NodeIdProtoOuterClass.NodeIdProto nodeId) {
+ if (nodeId.equals(NodeIdProtoOuterClass.NodeIdProto.getDefaultInstance())) {
+ return null;
+ }
+
+ return NodeId.nodeId(nodeId.getNodeId());
+ }
+
+ /**
+ * Translates {@link NodeId} to gRPC NodeId message.
+ *
+ * @param nodeId {@link NodeId}
+ * @return gRPC NodeId message
+ */
+ public static NodeIdProtoOuterClass.NodeIdProto translate(NodeId nodeId) {
+
+ if (nodeId != null) {
+ return NodeIdProtoOuterClass.NodeIdProto.newBuilder()
+ .setNodeId(nodeId.id())
+ .build();
+ }
+
+ return NodeIdProtoOuterClass.NodeIdProto.getDefaultInstance();
+ }
+
+ // Utility class not intended for instantiation.
+ private NodeIdProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/RoleInfoProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/RoleInfoProtoTranslator.java
new file mode 100644
index 0000000..d879a08
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/RoleInfoProtoTranslator.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.cluster;
+
+import com.google.common.collect.Lists;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.cluster.RoleInfo;
+import org.onosproject.grpc.cluster.models.RoleInfoProtoOuterClass;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * gRPC RoleInfoProto message to equivalent ONOS RoleInfo conversion related utilities.
+ */
+public final class RoleInfoProtoTranslator {
+
+ /**
+ * Translates gRPC RoleInfo to {@link RoleInfo}.
+ *
+ * @param roleInfo gRPC message
+ * @return {@link RoleInfo}
+ */
+ public static RoleInfo translate(RoleInfoProtoOuterClass.RoleInfoProto roleInfo) {
+ NodeId master = NodeIdProtoTranslator.translate(roleInfo.getMaster());
+
+ List<NodeId> backups = Lists.newArrayList();
+ backups = roleInfo.getBackupsList().stream().map(r ->
+ NodeIdProtoTranslator.translate(r)).collect(Collectors.toList());
+ return new RoleInfo(master, backups);
+ }
+
+ /**
+ * Translates {@link RoleInfo} to gRPC RoleInfo message.
+ *
+ * @param roleInfo {@link RoleInfo}
+ * @return gRPC RoleInfo message
+ */
+ public static RoleInfoProtoOuterClass.RoleInfoProto translate(RoleInfo roleInfo) {
+
+ if (roleInfo != null) {
+ RoleInfoProtoOuterClass.RoleInfoProto.Builder builder =
+ RoleInfoProtoOuterClass.RoleInfoProto.newBuilder();
+ builder.setMaster(NodeIdProtoTranslator.translate(roleInfo.master()));
+ roleInfo.backups().forEach(b -> builder.addBackups(NodeIdProtoTranslator.translate(b)));
+ return builder.build();
+ }
+
+ return RoleInfoProtoOuterClass.RoleInfoProto.getDefaultInstance();
+ }
+
+ // Utility class not intended for instantiation.
+ private RoleInfoProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/package-info.java
new file mode 100644
index 0000000..0f120f5
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/cluster/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS cluster models.
+ */
+package org.onosproject.incubator.protobuf.models.cluster;
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java
new file mode 100644
index 0000000..6fe0319
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationEnumsProtoTranslator.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.core;
+
+import org.onosproject.app.ApplicationState;
+import org.onosproject.core.ApplicationRole;
+import org.onosproject.grpc.app.models.ApplicationEnumsProto.ApplicationRoleProto;
+import org.onosproject.grpc.app.models.ApplicationEnumsProto.ApplicationStateProto;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC ApplicationEnumsProto message to equivalent ONOS Application Enums conversion related utilities.
+ */
+public final class ApplicationEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(ApplicationEnumsProtoTranslator.class);
+
+ /**
+ * Translates {@link ApplicationRole} to gRPC ApplicationRole.
+ *
+ * @param role {@link ApplicationRole}
+ * @return gRPC message
+ */
+ public static ApplicationRoleProto translate(ApplicationRole role) {
+
+ switch (role) {
+ case USER:
+ return ApplicationRoleProto.USER;
+ case ADMIN:
+ return ApplicationRoleProto.ADMIN;
+ case UNSPECIFIED:
+ return ApplicationRoleProto.UNSPECIFIED;
+
+ default:
+ log.warn("Unexpected application role: {}", role);
+ return ApplicationRoleProto.UNSPECIFIED;
+ }
+ }
+
+ /**
+ * Translates gRPC ApplicationRole to {@link ApplicationRole}.
+ *
+ * @param roleProto gRPC message
+ * @return {@link ApplicationRole}
+ */
+ public static Optional<ApplicationRole> translate(ApplicationRoleProto roleProto) {
+
+ switch (roleProto) {
+ case USER:
+ return Optional.of(ApplicationRole.USER);
+ case ADMIN:
+ return Optional.of(ApplicationRole.ADMIN);
+ case UNSPECIFIED:
+ return Optional.of(ApplicationRole.UNSPECIFIED);
+
+ default:
+ log.warn("Unexpected application role proto: {}", roleProto);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translate {@link ApplicationState} to gRPC ApplicationState.
+ *
+ * @param state {@link ApplicationState}
+ * @return gRPC message
+ */
+ public static ApplicationStateProto translate(ApplicationState state) {
+
+ switch (state) {
+ case ACTIVE:
+ return ApplicationStateProto.ACTIVE;
+ case INSTALLED:
+ return ApplicationStateProto.INSTALLED;
+
+ default:
+ log.warn("Unexpected application state: {}", state);
+ return ApplicationStateProto.INSTALLED;
+ }
+ }
+
+ /**
+ * Translate gRPC ApplicationState to {@link ApplicationState}.
+ *
+ * @param stateProto gRPC message
+ * @return {@link ApplicationState}
+ */
+ public static Optional<ApplicationState> translate(ApplicationStateProto stateProto) {
+
+ switch (stateProto) {
+ case ACTIVE:
+ return Optional.of(ApplicationState.ACTIVE);
+ case INSTALLED:
+ return Optional.of(ApplicationState.INSTALLED);
+
+ default:
+ log.warn("Unexpected application state proto: {}", stateProto);
+ return Optional.empty();
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private ApplicationEnumsProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationIdProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationIdProtoTranslator.java
new file mode 100644
index 0000000..e74ad7f
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationIdProtoTranslator.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.core;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.grpc.core.models.ApplicationIdProtoOuterClass.ApplicationIdProto;
+
+import static org.onosproject.grpc.core.models.ApplicationIdProtoOuterClass.ApplicationIdProto.getDefaultInstance;
+
+/**
+ * gRPC ApplicationIdProto message to equivalent ONOS ApplicationId conversion related utilities.
+ */
+public final class ApplicationIdProtoTranslator {
+
+ /**
+ * Translates gRPC ApplicationId to {@link ApplicationId}.
+ *
+ * @param applicationId gRPC message
+ * @return {@link ApplicationId}
+ */
+ public static ApplicationId translate(ApplicationIdProto applicationId) {
+
+ return new DefaultApplicationId(applicationId.getId(), applicationId.getName());
+ }
+
+ /**
+ * Translates {@link ApplicationId} to gRPC ApplicationId message.
+ *
+ * @param applicationId {@link ApplicationId}
+ * @return gRPC ApplicationId message
+ */
+ public static ApplicationIdProto translate(ApplicationId applicationId) {
+
+ if (applicationId != null) {
+ return ApplicationIdProto.newBuilder()
+ .setId(applicationId.id())
+ .setName(applicationId.name())
+ .build();
+ }
+
+ return getDefaultInstance();
+ }
+
+ // utility class not intended for instantiation.
+ private ApplicationIdProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java
new file mode 100644
index 0000000..25a95e4
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/ApplicationProtoTranslator.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.core;
+
+import com.google.common.collect.Sets;
+import org.onosproject.core.Application;
+import org.onosproject.core.DefaultApplication;
+import org.onosproject.grpc.core.models.ApplicationProtoOuterClass.ApplicationProto;
+import org.onosproject.incubator.protobuf.models.security.PermissionProtoTranslator;
+import org.onosproject.security.Permission;
+
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.onosproject.grpc.core.models.ApplicationProtoOuterClass.ApplicationProto.getDefaultInstance;
+
+/**
+ * gRPC ApplicationProto message to equivalent ONOS Application conversion related utilities.
+ */
+public final class ApplicationProtoTranslator {
+
+ /**
+ * Translates gRPC Application to {@link Application}.
+ *
+ * @param app gRPC message
+ * @return {@link Application}
+ */
+ public static Application translate(ApplicationProto app) {
+
+ Set<Permission> permissions = Sets.newHashSet();
+
+ app.getPermissionsList().forEach(p ->
+ permissions.add(PermissionProtoTranslator.translate(p)));
+
+ return DefaultApplication.builder()
+ .withAppId(ApplicationIdProtoTranslator.translate(app.getAppId()))
+ .withVersion(VersionProtoTranslator.translate(app.getVersion()))
+ .withTitle(app.getTitle())
+ .withDescription(app.getDescription())
+ .withOrigin(app.getOrigin())
+ .withCategory(app.getCategory())
+ .withUrl(app.getUrl())
+ .withReadme(app.getReadme())
+ .withIcon(app.toByteArray())
+ .withRole(ApplicationEnumsProtoTranslator.translate(app.getRole()).get())
+ .withPermissions(permissions)
+ .withFeatures(app.getFeaturesList())
+ .withFeaturesRepo(Optional.empty()) // TODO: need to add features repo
+ .withRequiredApps(app.getRequiredAppsList())
+ .build();
+ }
+
+ /**
+ * Translates {@link Application} to gRPC Application message.
+ *
+ * @param application {@link Application}
+ * @return gRPC message
+ */
+ public static ApplicationProto translate(Application application) {
+
+ if (application != null) {
+ return ApplicationProto.newBuilder()
+ .setAppId(ApplicationIdProtoTranslator.translate(application.id()))
+ .setCategory(application.category())
+ .setDescription(application.description())
+ .setOrigin(application.origin())
+ .setReadme(application.readme())
+ .setTitle(application.title())
+ .setUrl(application.url())
+ .setVersion(VersionProtoTranslator.translate(application.version()))
+ .setRole(ApplicationEnumsProtoTranslator.translate(application.role()))
+ .addAllFeatures(application.features())
+ .addAllPermissions(application.permissions().stream().map(p ->
+ PermissionProtoTranslator.translate(p)).collect(Collectors.toList()))
+ .addAllRequiredApps(application.requiredApps())
+ .build();
+ }
+
+ return getDefaultInstance();
+ }
+
+ // Utility class not intended for instantiation.
+ private ApplicationProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/VersionProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/VersionProtoTranslator.java
new file mode 100644
index 0000000..6e0c243
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/VersionProtoTranslator.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.core;
+
+import org.onosproject.core.Version;
+import org.onosproject.grpc.core.models.VersionProtoOuterClass.VersionProto;
+
+import static org.onosproject.grpc.core.models.VersionProtoOuterClass.VersionProto.getDefaultInstance;
+
+/**
+ * gRPC Version message to equivalent ONOS Version conversion related utilities.
+ */
+public final class VersionProtoTranslator {
+
+ /**
+ * Translates {@link Version} to gRPC version message.
+ *
+ * @param version {@link Version}
+ * @return gRPC message
+ */
+ public static VersionProto translate(Version version) {
+
+ if (version != null) {
+ return VersionProto.newBuilder()
+ .setMajor(version.major())
+ .setMinor(version.minor())
+ .setPatch(version.patch())
+ .setBuild(version.build())
+ .build();
+ }
+
+ return getDefaultInstance();
+ }
+
+ /**
+ * Translates gRPC version message to {@link Version}.
+ *
+ * @param version gRPC message
+ * @return {@link Version}
+ */
+ public static Version translate(VersionProto version) {
+
+ return Version.version(version.getMajor(), version.getMinor(),
+ version.getPatch(), version.getBuild());
+ }
+
+ // Utility class not intended for instantiation.
+ private VersionProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/package-info.java
new file mode 100644
index 0000000..c1de17f
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/core/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS core models.
+ */
+package org.onosproject.incubator.protobuf.models.core;
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/AnnotationsTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/AnnotationsTranslator.java
new file mode 100644
index 0000000..0b8cb03
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/AnnotationsTranslator.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.SparseAnnotations;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * gRPC message conversion related utilities for annotations service.
+ */
+public final class AnnotationsTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(AnnotationsTranslator.class);
+
+ /**
+ * Converts Annotations to Map of Strings.
+ *
+ * @param annotations {@link Annotations}
+ * @return Map of annotation key and values
+ */
+ public static Map<String, String> asMap(Annotations annotations) {
+ if (annotations instanceof DefaultAnnotations) {
+ return ((DefaultAnnotations) annotations).asMap();
+ }
+ Map<String, String> map = new HashMap<>();
+ annotations.keys()
+ .forEach(k -> map.put(k, annotations.value(k)));
+
+ return map;
+ }
+
+ /**
+ * Converts Map of Strings to {@link SparseAnnotations}.
+ *
+ * @param annotations Map of annotation key and values
+ * @return {@link SparseAnnotations}
+ */
+ public static SparseAnnotations asAnnotations(Map<String, String> annotations) {
+ DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
+ annotations.entrySet().forEach(e -> {
+ if (e.getValue() != null) {
+ builder.set(e.getKey(), e.getValue());
+ } else {
+ builder.remove(e.getKey());
+ }
+ });
+ return builder.build();
+ }
+
+ // Utility class not intended for instantiation.
+ private AnnotationsTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/ConnectPointProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/ConnectPointProtoTranslator.java
new file mode 100644
index 0000000..fd149b1
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/ConnectPointProtoTranslator.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.net.IpElementId;
+import org.onosproject.net.PortNumber;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC ConnectPoint message to org.onosproject.net.ConnectPoint conversion related utilities.
+ */
+public final class ConnectPointProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(ConnectPointProtoTranslator.class);
+
+ /**
+ * Translates gRPC ConnectPoint message to Optional of {@link org.onosproject.net.ConnectPoint}.
+ *
+ * @param connectPoint gRPC message
+ * @return Optional of equivalent {@link org.onosproject.net.ConnectPoint} or empty if ElementId is not recognized
+ */
+ public static Optional<ConnectPoint> translate(ConnectPointProto connectPoint) {
+ switch (connectPoint.getElementIdCase()) {
+ case DEVICE_ID:
+ return Optional.of(new ConnectPoint(DeviceId.deviceId(connectPoint.getDeviceId()),
+ PortNumber.portNumber(connectPoint.getPortNumber())));
+ case HOST_ID:
+ return Optional.of(new ConnectPoint(HostId.hostId(connectPoint.getHostId()),
+ PortNumber.portNumber(connectPoint.getPortNumber())));
+ case IP_ELEMENT_ID:
+ return Optional.of(new ConnectPoint(IpElementId.ipElement(IpAddress
+ .valueOf(connectPoint
+ .getIpElementId()
+ )),
+ PortNumber.portNumber(connectPoint.getPortNumber())));
+ default:
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates {@link org.onosproject.net.ConnectPoint} to gRPC ConnectPoint message.
+ *
+ * @param connectPoint {@link org.onosproject.net.ConnectPoint}
+ * @return gRPC ConnectPoint message
+ */
+ public static ConnectPointProto translate(ConnectPoint connectPoint) {
+
+ if (connectPoint.elementId() instanceof DeviceId) {
+ return ConnectPointProto.newBuilder().setDeviceId(connectPoint.deviceId().toString())
+ .setPortNumber(connectPoint.port().toString())
+ .build();
+ } else if (connectPoint.elementId() instanceof HostId) {
+ return ConnectPointProto.newBuilder().setHostId(connectPoint.hostId().toString())
+ .setPortNumber(connectPoint.port().toString())
+ .build();
+ } else if (connectPoint.ipElementId() != null) {
+ return ConnectPointProto.newBuilder().setIpElementId(connectPoint.ipElementId().toString())
+ .setPortNumber(connectPoint.port().toString())
+ .build();
+ } else {
+ log.warn("Unrecognized ElementId", connectPoint);
+ throw new IllegalArgumentException("Unrecognized ElementId");
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private ConnectPointProtoTranslator() {}
+}
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostIdProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostIdProtoTranslator.java
new file mode 100644
index 0000000..859cca4
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostIdProtoTranslator.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.grpc.net.models.HostIdProtoOuterClass.HostIdProto;
+import org.onosproject.net.HostId;
+
+/**
+ * gRPC HostIdProto message to equivalent ONOS HostId conversion related utilities.
+ */
+public final class HostIdProtoTranslator {
+
+ /**
+ * Translates gRPC HostId to {@link HostId}.
+ *
+ * @param hostId gRPC message
+ * @return {@link HostId}
+ */
+ public static HostId translate(HostIdProto hostId) {
+
+ if (hostId.equals(HostIdProto.getDefaultInstance())) {
+ return null;
+ }
+
+ return HostId.hostId(MacAddress.valueOf(hostId.getMac()), VlanId.vlanId((short) hostId.getVlanId()));
+ }
+
+ /**
+ * Translates {@link HostId} to gRPC HostId message.
+ *
+ * @param hostId {@link HostId}
+ * @return gRPC HostId message
+ */
+ public static HostIdProto translate(HostId hostId) {
+
+ if (hostId != null) {
+ return HostIdProto.newBuilder()
+ .setMac(hostId.mac().toString())
+ .setVlanId(hostId.vlanId().toShort())
+ .build();
+ }
+
+ return HostIdProto.getDefaultInstance();
+ }
+
+ // Utility class not intended for instantiation.
+ private HostIdProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostLocationProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostLocationProtoTranslator.java
new file mode 100644
index 0000000..098a276
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostLocationProtoTranslator.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onosproject.grpc.net.models.ConnectPointProtoOuterClass.ConnectPointProto;
+import org.onosproject.grpc.net.models.HostLocationProtoOuterClass.HostLocationProto;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostLocation;
+import org.onosproject.net.PortNumber;
+
+/**
+ * gRPC HostLocationProto message to equivalent ONOS Host location conversion related utilities.
+ */
+public final class HostLocationProtoTranslator {
+
+ /**
+ * Translates gRPC HostLocation to {@link HostLocation}.
+ *
+ * @param hostLocation gRPC message
+ * @return {@link HostLocation}
+ */
+ public static HostLocation translate(HostLocationProto hostLocation) {
+
+ if (hostLocation.equals(HostLocationProto.getDefaultInstance())) {
+ return null;
+ }
+
+ return new HostLocation(DeviceId.deviceId(hostLocation.getConnectPoint().getDeviceId()),
+ PortNumber.portNumber(hostLocation.getConnectPoint().getPortNumber()), 0L);
+ }
+
+ /**
+ * Translates {@link HostLocation} to gRPC HostLocation message.
+ *
+ * @param hostLocation {@link HostLocation}
+ * @return gRPC HostLocation message
+ */
+ public static HostLocationProto translate(HostLocation hostLocation) {
+
+ if (hostLocation != null) {
+ return HostLocationProto.newBuilder()
+ .setConnectPoint(ConnectPointProto.newBuilder()
+ .setDeviceId(hostLocation.deviceId().toString())
+ .setPortNumber(hostLocation.port().toString()))
+ .setTime(hostLocation.time())
+ .build();
+ }
+
+ return HostLocationProto.getDefaultInstance();
+ }
+
+ // Utility class not intended for instantiation.
+ private HostLocationProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostProtoTranslator.java
new file mode 100644
index 0000000..c12fd7f
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/HostProtoTranslator.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.grpc.net.models.HostProtoOuterClass.HostProto;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultHost;
+import org.onosproject.net.Host;
+
+import java.util.stream.Collectors;
+
+/**
+ * gRPC HostProto message to equivalent ONOS Host conversion related utilities.
+ */
+public final class HostProtoTranslator {
+
+
+ /**
+ * Translates {@link Host} to gRPC Host message.
+ *
+ * @param host {@link Host}
+ * @return gRPC HostProto message
+ */
+ public static HostProto translate(Host host) {
+
+ if (host != null) {
+ return HostProto.newBuilder()
+ .setHostId(HostIdProtoTranslator.translate(host.id()))
+ .setConfigured(host.configured())
+ .setVlan(host.vlan().toShort())
+ .addAllIpAddresses(host.ipAddresses().stream()
+ .map(IpAddress::toString)
+ .collect(Collectors.toList()))
+ .setLocation(HostLocationProtoTranslator.translate(host.location()))
+ .build();
+ }
+
+ return HostProto.getDefaultInstance();
+ }
+
+ /**
+ * Translates gRPC Host message to {@link Host}.
+ *
+ * @param host gRPC message
+ * @return {@link Host}
+ */
+ public static Host translate(HostProto host) {
+ if (host.equals(HostProto.getDefaultInstance())) {
+ return null;
+ }
+
+ return new DefaultHost(ProviderIdProtoTranslator.translate(host.getProviderId()),
+ HostIdProtoTranslator.translate(host.getHostId()),
+ MacAddress.valueOf(host.getHostId().getMac()),
+ VlanId.vlanId((short) host.getVlan()),
+ HostLocationProtoTranslator.translate(host.getLocation()),
+ host.getIpAddressesList().stream().map(x -> IpAddress.valueOf(x))
+ .collect(Collectors.toSet()),
+ DefaultAnnotations.builder().putAll(host.getAnnotationsMap()).build());
+ }
+
+ // Utility class not intended for instantiation.
+ private HostProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java
new file mode 100644
index 0000000..770d835
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/LinkProtoTranslator.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onosproject.incubator.protobuf.models.net.link.LinkEnumsProtoTranslator;
+import org.onosproject.grpc.net.models.LinkProtoOuterClass;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.DefaultLink;
+import org.onosproject.net.Link;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.provider.ProviderId;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * gRPC LinkProto message to equivalent ONOS Link conversion related utilities.
+ */
+public final class LinkProtoTranslator {
+
+ /**
+ * Translates gRPC LinkCore message to {@link Link}.
+ *
+ * @param link gRPC message
+ * @return {@link Link} null if link is a default instance
+ */
+ public static Link translate(LinkProtoOuterClass.LinkProto link) {
+ if (link.equals(LinkProtoOuterClass.LinkProto.getDefaultInstance())) {
+ return null;
+ }
+ ProviderId providerId = ProviderIdProtoTranslator.translate(link.getProviderId());
+ Link.State state = LinkEnumsProtoTranslator.translate(link.getState()).get();
+ ConnectPoint src = ConnectPointProtoTranslator.translate(link.getSrc()).get();
+ ConnectPoint dst = ConnectPointProtoTranslator.translate(link.getDst()).get();
+ Link.Type type = LinkEnumsProtoTranslator.translate(link.getType()).get();
+ Annotations annots = asAnnotations(link.getAnnotations());
+ Boolean isExpected = link.getIsExpected();
+ return DefaultLink.builder().state(state)
+ .annotations(annots)
+ .providerId(providerId)
+ .src(src)
+ .dst(dst)
+ .type(type)
+ .isExpected(isExpected)
+ .build();
+ }
+
+ /**
+ * Translates {@link Link} to gRPC LinkCore message.
+ *
+ * @param link {@link Link}
+ * @return gRPC LinkCore message
+ */
+ public static LinkProtoOuterClass.LinkProto translate(Link link) {
+ if (link == null) {
+ return LinkProtoOuterClass.LinkProto.getDefaultInstance();
+ }
+ return LinkProtoOuterClass.LinkProto.newBuilder()
+ .setProviderId(ProviderIdProtoTranslator.translate(link.providerId()))
+ .setState(LinkEnumsProtoTranslator.translate(link.state()))
+ .setSrc(ConnectPointProtoTranslator.translate(link.src()))
+ .setDst(ConnectPointProtoTranslator.translate(link.dst()))
+ .setType(LinkEnumsProtoTranslator.translate(link.type()))
+ .setIsExpected(link.isExpected())
+ .build();
+ }
+
+ // may be this can be moved to Annotation itself or AnnotationsUtils
+
+ /**
+ * Converts Map of Strings to {@link SparseAnnotations}.
+ *
+ * @param annotations Map of annotation key and values
+ * @return {@link SparseAnnotations}
+ */
+ public static SparseAnnotations asAnnotations(Map<String, String> annotations) {
+ DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
+ annotations.entrySet().forEach(e -> {
+ if (e.getValue() != null) {
+ builder.set(e.getKey(), e.getValue());
+ } else {
+ builder.remove(e.getKey());
+ }
+ });
+ return builder.build();
+ }
+
+ /**
+ * Converts Annotations to Map of Strings.
+ *
+ * @param annotations {@link Annotations}
+ * @return Map of annotation key and values
+ */
+ public static Map<String, String> asMap(Annotations annotations) {
+ if (annotations instanceof DefaultAnnotations) {
+ return ((DefaultAnnotations) annotations).asMap();
+ }
+ Map<String, String> map = new HashMap<>();
+ annotations.keys()
+ .forEach(k -> map.put(k, annotations.value(k)));
+
+ return map;
+ }
+
+ // Utility class not intended for instantiation.
+ private LinkProtoTranslator() {
+ }
+
+}
+
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/MastershipRoleProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/MastershipRoleProtoTranslator.java
new file mode 100644
index 0000000..d10c621
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/MastershipRoleProtoTranslator.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onosproject.grpc.net.models.MastershipRoleProtoOuterClass;
+import org.onosproject.net.MastershipRole;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC MastershipRoleProto message to equivalent ONOS MastershipRole conversion related utilities.
+ */
+public final class MastershipRoleProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(MastershipRoleProtoTranslator.class);
+
+ /**
+ * Translates {@link MastershipRole} to gRPC MastershipRole.
+ *
+ * @param mastershipRole {@link MastershipRole}
+ * @return gRPC message
+ */
+ public static MastershipRoleProtoOuterClass.MastershipRoleProto translate(MastershipRole mastershipRole) {
+
+ switch (mastershipRole) {
+ case MASTER:
+ return MastershipRoleProtoOuterClass.MastershipRoleProto.MASTER;
+ case STANDBY:
+ return MastershipRoleProtoOuterClass.MastershipRoleProto.STANDBY;
+ case NONE:
+ return MastershipRoleProtoOuterClass.MastershipRoleProto.NONE;
+
+ default:
+ log.warn("Unexpected mastership role: {}", mastershipRole);
+ return MastershipRoleProtoOuterClass.MastershipRoleProto.NONE;
+ }
+ }
+
+ /**
+ * Translate gRPC MastershipRole to {@link MastershipRole}.
+ *
+ * @param mastershipRole gRPC message
+ * @return {@link MastershipRole}
+ */
+ public static Optional<Object> translate(MastershipRoleProtoOuterClass.MastershipRoleProto mastershipRole) {
+
+ switch (mastershipRole) {
+ case MASTER:
+ return Optional.of(MastershipRole.MASTER);
+ case STANDBY:
+ return Optional.of(MastershipRole.STANDBY);
+ case UNRECOGNIZED:
+ return Optional.of(MastershipRole.NONE);
+
+ default:
+ log.warn("Unexpected mastership role: {}", mastershipRole);
+ return Optional.empty();
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private MastershipRoleProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/ProviderIdProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/ProviderIdProtoTranslator.java
new file mode 100644
index 0000000..8ee4fe5
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/ProviderIdProtoTranslator.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net;
+
+import org.onosproject.grpc.net.models.ProviderIdProtoOuterClass;
+import org.onosproject.net.provider.ProviderId;
+
+/**
+ * gRPC ProviderId message to org.onosproject.net.provider.ProviderId conversion related utilities.
+ */
+public final class ProviderIdProtoTranslator {
+
+ /**
+ * Translates gRPC ProviderId message to {@link org.onosproject.net.provider.ProviderId}.
+ *
+ * @param providerId gRPC ProviderId message
+ * @return {@link org.onosproject.net.provider.ProviderId} or null if providerId is a default instance
+ */
+ public static ProviderId translate(ProviderIdProtoOuterClass.ProviderIdProto providerId) {
+ if (providerId.equals(ProviderIdProtoOuterClass.ProviderIdProto.getDefaultInstance())) {
+ return null;
+ }
+ return new ProviderId(providerId.getScheme(), providerId.getId(), providerId.getAncillary());
+ }
+
+ /**
+ * Translates {@link org.onosproject.net.provider.ProviderId} to gRPC ProviderId message.
+ *
+ * @param providerId {@link org.onosproject.net.provider.ProviderId}
+ * @return gRPC ProviderId message
+ */
+ public static ProviderIdProtoOuterClass.ProviderIdProto translate(ProviderId providerId) {
+ if (providerId == null) {
+ return ProviderIdProtoOuterClass.ProviderIdProto.getDefaultInstance();
+ }
+ return ProviderIdProtoOuterClass.ProviderIdProto.newBuilder()
+ .setScheme(providerId.scheme())
+ .setId(providerId.id())
+ .setAncillary(providerId.isAncillary())
+ .build();
+ }
+
+
+ // Utility class not intended for instantiation.
+ private ProviderIdProtoTranslator() {}
+
+}
+
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java
new file mode 100644
index 0000000..f426982
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/RegionProtoTranslator.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net;
+
+import com.google.common.base.Strings;
+import org.onosproject.incubator.protobuf.models.net.region.RegionEnumsProtoTranslator;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.grpc.net.models.RegionProtoOuterClass;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.region.DefaultRegion;
+import org.onosproject.net.region.Region;
+import org.onosproject.net.region.RegionId;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * gRPC Region message to @link org.onosproject.net.region.Region conversion related utilities for region service.
+ */
+public final class RegionProtoTranslator {
+
+ /**
+ * Translates gRPC RegionProto message to {@link org.onosproject.net.region.Region}.
+ *
+ * @param region gRPC message
+ * @return {@link org.onosproject.net.region.Region}
+ */
+ public static Region translate(RegionProtoOuterClass.RegionProto region) {
+ RegionId id = RegionId.regionId(region.getRegionId());
+ Region.Type type = RegionEnumsProtoTranslator.translate(region.getType()).get();
+ String name = Strings.nullToEmpty(region.getName());
+
+ List<Set<NodeId>> masters = new ArrayList<>();
+
+ region.getMastersList().forEach(s -> {
+ Set<NodeId> nodeIdSet = new HashSet<NodeId>();
+ s.getNodeIdList().forEach(n -> {
+ nodeIdSet.add(new NodeId(n));
+ });
+ masters.add(nodeIdSet);
+ });
+
+ Annotations annots = AnnotationsTranslator.asAnnotations(region.getAnnotations());
+
+ return new DefaultRegion(id, name, type, annots, masters);
+ }
+
+ /**
+ * Translates {@link org.onosproject.net.region.Region} to gRPC RegionProto message.
+ *
+ * @param region {@link org.onosproject.net.region.Region}
+ * @return gRPC RegionProto message
+ */
+ public static RegionProtoOuterClass.RegionProto translate(Region region) {
+ return RegionProtoOuterClass.RegionProto.newBuilder()
+ .setRegionId(region.id().toString())
+ .setType(RegionEnumsProtoTranslator.translate(region.type()))
+ .setName(region.name().isEmpty() ? null : region.name())
+ .addAllMasters(region.masters()
+ .stream()
+ .map(s -> RegionProtoOuterClass.RegionProto.NodeIdSet
+ .newBuilder()
+ .addAllNodeId(s.stream().map(id ->
+ id.toString()).collect(Collectors.toList()))
+ .build())
+ .collect(Collectors.toList()))
+ .build();
+ }
+
+ // Utility class not intended for instantiation.
+ private RegionProtoTranslator() {}
+
+}
+
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/DeviceProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/DeviceProtoTranslator.java
new file mode 100644
index 0000000..90d10f5
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/DeviceProtoTranslator.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.device;
+
+import org.onlab.packet.ChassisId;
+import org.onosproject.grpc.net.device.models.DeviceDescriptionProtoOuterClass;
+import org.onosproject.grpc.net.device.models.DeviceDescriptionProtoOuterClass.DeviceDescriptionProto;
+import org.onosproject.grpc.net.device.models.DeviceEnumsProto.DeviceTypeProto;
+import org.onosproject.incubator.protobuf.models.net.AnnotationsTranslator;
+import org.onosproject.net.Device.Type;
+import org.onosproject.net.device.DefaultDeviceDescription;
+import org.onosproject.net.device.DeviceDescription;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+
+/**
+ * gRPC message conversion related utilities for device service.
+ */
+public final class DeviceProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(DeviceProtoTranslator.class);
+
+ /**
+ * Translates gRPC DeviceDescription to {@link DeviceDescriptionProtoOuterClass}.
+ *
+ * @param deviceDescription gRPC message
+ * @return {@link DeviceDescriptionProtoOuterClass}
+ */
+ public static DeviceDescription translate(
+ DeviceDescriptionProto deviceDescription) {
+ URI uri = URI.create(deviceDescription.getDeviceUri());
+ Type type = translate(deviceDescription.getType());
+ String manufacturer = deviceDescription.getManufacturer();
+ String hwVersion = deviceDescription.getHwVersion();
+ String swVersion = deviceDescription.getSwVersion();
+ String serialNumber = deviceDescription.getSerialNumber();
+ ChassisId chassis = new ChassisId(deviceDescription.getChassisId());
+ boolean defaultAvailable = deviceDescription.getIsDefaultAvailable();
+ return new DefaultDeviceDescription(uri, type, manufacturer,
+ hwVersion, swVersion, serialNumber,
+ chassis,
+ defaultAvailable,
+ AnnotationsTranslator.asAnnotations(deviceDescription.getAnnotationsMap()));
+ }
+
+ /**
+ * Translates {@link DeviceDescription} to gRPC DeviceDescription message.
+ *
+ * @param deviceDescription {@link DeviceDescription}
+ * @return gRPC DeviceDescription message
+ */
+ public static DeviceDescriptionProto translate(
+ DeviceDescription deviceDescription) {
+
+ return DeviceDescriptionProto.newBuilder()
+ .setDeviceUri(deviceDescription.deviceUri().toString())
+ .setType(translate(deviceDescription.type()))
+ .setManufacturer(deviceDescription.manufacturer())
+ .setHwVersion(deviceDescription.hwVersion())
+ .setSwVersion(deviceDescription.swVersion())
+ .setSerialNumber(deviceDescription.serialNumber())
+ .setChassisId(deviceDescription.chassisId().toString())
+ .setIsDefaultAvailable(deviceDescription.isDefaultAvailable())
+ .putAllAnnotations(AnnotationsTranslator.asMap(deviceDescription.annotations()))
+ .build();
+ }
+
+
+ /**
+ * Translates gRPC DeviceType to {@link Type}.
+ *
+ * @param type gRPC message
+ * @return {@link Type}
+ */
+ public static Type translate(DeviceTypeProto type) {
+ switch (type) {
+ case BALANCER:
+ return Type.BALANCER;
+ case CONTROLLER:
+ return Type.CONTROLLER;
+ case FIBER_SWITCH:
+ return Type.FIBER_SWITCH;
+ case FIREWALL:
+ return Type.FIREWALL;
+ case IDS:
+ return Type.IDS;
+ case IPS:
+ return Type.IPS;
+ case MICROWAVE:
+ return Type.MICROWAVE;
+ case OTHER:
+ return Type.OTHER;
+ case OTN:
+ return Type.OTN;
+ case ROADM:
+ return Type.ROADM;
+ case ROADM_OTN:
+ return Type.ROADM_OTN;
+ case ROUTER:
+ return Type.ROUTER;
+ case SWITCH:
+ return Type.SWITCH;
+ case VIRTUAL_DEVICE:
+ return Type.VIRTUAL;
+
+ case UNRECOGNIZED:
+ default:
+ log.warn("Unexpected DeviceType: {}", type);
+ return Type.OTHER;
+ }
+ }
+
+ /**
+ * Translates {@link Type} to gRPC DeviceType.
+ *
+ * @param type {@link Type}
+ * @return gRPC message
+ */
+ public static DeviceTypeProto translate(Type type) {
+ switch (type) {
+ case BALANCER:
+ return DeviceTypeProto.BALANCER;
+ case CONTROLLER:
+ return DeviceTypeProto.CONTROLLER;
+ case FIBER_SWITCH:
+ return DeviceTypeProto.FIBER_SWITCH;
+ case FIREWALL:
+ return DeviceTypeProto.FIREWALL;
+ case IDS:
+ return DeviceTypeProto.IDS;
+ case IPS:
+ return DeviceTypeProto.IPS;
+ case MICROWAVE:
+ return DeviceTypeProto.MICROWAVE;
+ case OTHER:
+ return DeviceTypeProto.OTHER;
+ case OTN:
+ return DeviceTypeProto.OTN;
+ case ROADM:
+ return DeviceTypeProto.ROADM;
+ case ROADM_OTN:
+ return DeviceTypeProto.ROADM_OTN;
+ case ROUTER:
+ return DeviceTypeProto.ROUTER;
+ case SWITCH:
+ return DeviceTypeProto.SWITCH;
+ case VIRTUAL:
+ return DeviceTypeProto.VIRTUAL_DEVICE;
+
+ default:
+ log.warn("Unexpected Device.Type: {}", type);
+ return DeviceTypeProto.OTHER;
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private DeviceProtoTranslator() {
+ }
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java
new file mode 100644
index 0000000..ff39987
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/PortProtoTranslator.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.device;
+
+import org.onosproject.grpc.net.device.models.PortDescriptionProtoOuterClass.PortDescriptionProto;
+import org.onosproject.grpc.net.device.models.PortEnumsProto;
+import org.onosproject.grpc.net.device.models.PortStatisticsProtoOuterClass;
+import org.onosproject.grpc.net.device.models.PortStatisticsProtoOuterClass.PortStatisticsProto;
+import org.onosproject.incubator.protobuf.models.net.AnnotationsTranslator;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.DefaultPortStatistics;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.device.PortStatistics;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC message conversion related utilities for port service.
+ */
+public final class PortProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(PortProtoTranslator.class);
+
+ /**
+ * Translates gRPC PortDescription message to {@link PortDescription}.
+ *
+ * @param portDescription gRPC message
+ * @return {@link PortDescription}
+ */
+ public static PortDescription translate(PortDescriptionProto portDescription) {
+ PortNumber number = PortNumber.fromString(portDescription.getPortNumber());
+ boolean isEnabled = portDescription.getIsEnabled();
+ Port.Type type = translate(portDescription.getType()).get();
+ long portSpeed = portDescription.getPortSpeed();
+ SparseAnnotations annotations = AnnotationsTranslator.asAnnotations(portDescription.getAnnotationsMap());
+ // TODO How to deal with more specific Port...
+ return DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled)
+ .type(type).portSpeed(portSpeed).annotations(annotations)
+ .build();
+ }
+
+ /**
+ * Translates {@link PortDescription} to gRPC PortDescription message.
+ *
+ * @param portDescription {@link PortDescription}
+ * @return gRPC PortDescription message
+ */
+ public static PortDescriptionProto translate(PortDescription portDescription) {
+ return PortDescriptionProto.newBuilder()
+ .setPortNumber(portDescription.portNumber().toString())
+ .setIsEnabled(portDescription.isEnabled())
+ .setType(translate(portDescription.type()))
+ .setPortSpeed(portDescription.portSpeed())
+ .putAllAnnotations(AnnotationsTranslator.asMap(portDescription.annotations()))
+ .build();
+ }
+
+ /**
+ * Translates gRPC PortType to {@link Port.Type}.
+ *
+ * @param type gRPC message
+ * @return {@link Port.Type}
+ */
+ public static Optional<Port.Type> translate(PortEnumsProto.PortTypeProto type) {
+ switch (type) {
+ case COPPER:
+ return Optional.of(Port.Type.COPPER);
+ case FIBER:
+ return Optional.of(Port.Type.FIBER);
+ case OCH:
+ return Optional.of(Port.Type.OCH);
+ case ODUCLT:
+ return Optional.of(Port.Type.ODUCLT);
+ case OMS:
+ return Optional.of(Port.Type.OMS);
+ case PACKET:
+ return Optional.of(Port.Type.PACKET);
+ case VIRTUAL_PORT:
+ return Optional.of(Port.Type.VIRTUAL);
+
+ default:
+ log.warn("Unexpected PortType: {}", type);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates {@link Port.Type} to gRPC PortType.
+ *
+ * @param type {@link Port.Type}
+ * @return gRPC message
+ */
+ public static PortEnumsProto.PortTypeProto translate(Port.Type type) {
+ switch (type) {
+ case COPPER:
+ return PortEnumsProto.PortTypeProto.COPPER;
+ case FIBER:
+ return PortEnumsProto.PortTypeProto.FIBER;
+ case OCH:
+ return PortEnumsProto.PortTypeProto.OCH;
+ case ODUCLT:
+ return PortEnumsProto.PortTypeProto.ODUCLT;
+ case OMS:
+ return PortEnumsProto.PortTypeProto.OMS;
+ case PACKET:
+ return PortEnumsProto.PortTypeProto.PACKET;
+ case VIRTUAL:
+ return PortEnumsProto.PortTypeProto.VIRTUAL_PORT;
+
+ default:
+ log.warn("Unexpected Port.Type: {}", type);
+ return PortEnumsProto.PortTypeProto.UNRECOGNIZED;
+ }
+ }
+
+ /**
+ * Translates gRPC PortStatistics message to {@link PortStatisticsProtoOuterClass}.
+ *
+ * @param portStatistics gRPC PortStatistics message
+ * @return {@link PortStatisticsProtoOuterClass}
+ */
+ public static PortStatistics translate(PortStatisticsProto portStatistics) {
+ // TODO implement adding missing fields
+ return DefaultPortStatistics.builder()
+ .setPort(portStatistics.getPort())
+ .setPacketsReceived(portStatistics.getPacketsReceived())
+ .setPacketsSent(portStatistics.getPacketsSent())
+ .build();
+ }
+
+ /**
+ * Translates {@link PortStatistics} to gRPC PortStatistics message.
+ *
+ * @param portStatistics {@link PortStatistics}
+ * @return gRPC PortStatistics message
+ */
+ public static PortStatisticsProto translate(PortStatistics portStatistics) {
+ // TODO implement adding missing fields
+ return PortStatisticsProto.newBuilder()
+ .setPort(portStatistics.port())
+ .setPacketsReceived(portStatistics.packetsReceived())
+ .setPacketsSent(portStatistics.packetsSent())
+ .build();
+ }
+
+ // Utility class not intended for instantiation.
+ private PortProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/package-info.java
new file mode 100644
index 0000000..5239102
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/device/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS device models.
+ */
+package org.onosproject.incubator.protobuf.models.net.device;
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java
new file mode 100644
index 0000000..f6c590b
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryEnumsProtoTranslator.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.flow;
+
+import org.onosproject.grpc.net.flow.models.FlowEntryEnumsProto;
+import org.onosproject.net.flow.FlowEntry.FlowEntryState;
+import org.onosproject.net.flow.FlowEntry.FlowLiveType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+
+/**
+ * gRPC FlowEntryEnumsProto message to equivalent ONOS FlowEntry enums conversion related utilities.
+ */
+public final class FlowEntryEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(FlowEntryEnumsProtoTranslator.class);
+
+ /**
+ * Translates {@link FlowEntryState} to gRPC FlowEntryState.
+ *
+ * @param flowEntryState {@link FlowEntryState}
+ * @return gRPC message
+ */
+ public static FlowEntryEnumsProto.FlowEntryStateProto translate(FlowEntryState flowEntryState) {
+
+ switch (flowEntryState) {
+ case PENDING_ADD:
+ return FlowEntryEnumsProto.FlowEntryStateProto.PENDING_ADD;
+ case ADDED:
+ return FlowEntryEnumsProto.FlowEntryStateProto.ADDED;
+ case PENDING_REMOVE:
+ return FlowEntryEnumsProto.FlowEntryStateProto.PENDING_REMOVE;
+ case REMOVED:
+ return FlowEntryEnumsProto.FlowEntryStateProto.REMOVED;
+ case FAILED:
+ return FlowEntryEnumsProto.FlowEntryStateProto.FAILED;
+
+ default:
+ log.warn("Unexpected flow entry state: {}", flowEntryState);
+ return FlowEntryEnumsProto.FlowEntryStateProto.UNRECOGNIZED;
+ }
+ }
+
+ /**
+ * Translates gRPC FlowEntryState to {@link FlowEntryState}.
+ *
+ * @param flowEntryState gRPC message
+ * @return {@link FlowEntryState}
+ */
+ public static Optional<FlowEntryState> translate(FlowEntryEnumsProto.FlowEntryStateProto flowEntryState) {
+
+ switch (flowEntryState) {
+ case PENDING_ADD:
+ return Optional.of(FlowEntryState.PENDING_ADD);
+ case ADDED:
+ return Optional.of(FlowEntryState.ADDED);
+ case PENDING_REMOVE:
+ return Optional.of(FlowEntryState.PENDING_REMOVE);
+ case REMOVED:
+ return Optional.of(FlowEntryState.REMOVED);
+ case FAILED:
+ return Optional.of(FlowEntryState.FAILED);
+
+ default:
+ log.warn("Unexpected flow entry state: {}", flowEntryState);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates {@link FlowLiveType} to gRPC FlowLiveType.
+ *
+ * @param flowLiveType {@link FlowLiveType}
+ * @return gRPC message
+ */
+ public static FlowEntryEnumsProto.FlowLiveTypeProto translate(FlowLiveType flowLiveType) {
+
+ switch (flowLiveType) {
+ case IMMEDIATE:
+ return FlowEntryEnumsProto.FlowLiveTypeProto.IMMEDIATE;
+ case SHORT:
+ return FlowEntryEnumsProto.FlowLiveTypeProto.SHORT;
+ case MID:
+ return FlowEntryEnumsProto.FlowLiveTypeProto.MID;
+ case LONG:
+ return FlowEntryEnumsProto.FlowLiveTypeProto.LONG;
+ case UNKNOWN:
+ return FlowEntryEnumsProto.FlowLiveTypeProto.UNKNOWN;
+
+ default:
+ log.warn("Unexpected flow live type : {}", flowLiveType);
+ return FlowEntryEnumsProto.FlowLiveTypeProto.UNRECOGNIZED;
+ }
+ }
+
+ /**
+ * Translates gRPC FlowLiveType to {@link FlowLiveType}.
+ *
+ * @param flowLiveType gRPC message
+ * @return {@link FlowLiveType}
+ */
+ public static Optional<FlowLiveType> translate(FlowEntryEnumsProto.FlowLiveTypeProto flowLiveType) {
+
+ switch (flowLiveType) {
+ case IMMEDIATE:
+ return Optional.of(FlowLiveType.IMMEDIATE);
+ case SHORT:
+ return Optional.of(FlowLiveType.SHORT);
+ case MID:
+ return Optional.of(FlowLiveType.MID);
+ case LONG:
+ return Optional.of(FlowLiveType.LONG);
+ case UNKNOWN:
+ return Optional.of(FlowLiveType.UNKNOWN);
+
+ default:
+ log.warn("Unexpected flow live type : {}", flowLiveType);
+ return Optional.empty();
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private FlowEntryEnumsProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java
new file mode 100644
index 0000000..80ec629
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowEntryProtoTranslator.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.flow;
+
+import org.onosproject.grpc.net.flow.models.FlowEntryProtoOuterClass.FlowEntryProto;
+import org.onosproject.net.flow.DefaultFlowEntry;
+import org.onosproject.net.flow.FlowEntry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * gRPC FlowEntryProto message to equivalent ONOS FlowEntry conversion related utilities.
+ */
+public final class FlowEntryProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(FlowEntryProtoTranslator.class);
+
+ /**
+ * Translates {@link FlowEntry} to gRPC FlowEntryProto.
+ *
+ * @param flowEntry {@link FlowEntry}
+ * @return gRPC message
+ */
+ public static FlowEntryProto translate(FlowEntry flowEntry) {
+
+ if (flowEntry != null) {
+ FlowEntryProto.Builder builder = FlowEntryProto.newBuilder();
+ builder.setLife(flowEntry.life())
+ .setPackets(flowEntry.packets())
+ .setBytes(flowEntry.bytes())
+ .setLastSeen(flowEntry.lastSeen())
+ .setErrType(flowEntry.errType())
+ .setErrCode(flowEntry.errCode())
+ .setState(FlowEntryEnumsProtoTranslator.translate(flowEntry.state()))
+ .setLiveType(FlowEntryEnumsProtoTranslator.translate(flowEntry.liveType()));
+ return builder.build();
+ }
+
+ return FlowEntryProto.getDefaultInstance();
+ }
+
+ /**
+ * Translates gRPC FlowEntry to {@link FlowEntry}.
+ *
+ * @param flowEntry gRPC message
+ * @return {@link FlowEntry}
+ */
+ public static FlowEntry translate(FlowEntryProto flowEntry) {
+ if (flowEntry.equals(FlowEntryProto.getDefaultInstance())) {
+ return null;
+ }
+
+ FlowEntry.FlowEntryState state =
+ FlowEntryEnumsProtoTranslator.translate(flowEntry.getState()).get();
+ FlowEntry.FlowLiveType liveType =
+ FlowEntryEnumsProtoTranslator.translate(flowEntry.getLiveType()).get();
+
+ // TODO: need to instantiate FlowRule later
+ return new DefaultFlowEntry(null, state, flowEntry.getLife(), liveType,
+ flowEntry.getPackets(), flowEntry.getBytes());
+ }
+
+ // Utility class not intended for instantiation.
+ private FlowEntryProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java
new file mode 100644
index 0000000..12ddf29
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleEnumsProtoTranslator.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.flow;
+
+import org.onosproject.grpc.net.flow.models.FlowRuleEnumsProto;
+import org.onosproject.net.flow.FlowRule.FlowRemoveReason;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC FlowRuleEnumsProto message to equivalent ONOS FlowRule enums conversion related utilities.
+ */
+public final class FlowRuleEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(FlowRuleEnumsProtoTranslator.class);
+
+ /**
+ * Translates {@link FlowRemoveReason} to gRPC FlowRemoveReason.
+ *
+ * @param flowRemoveReason {@link FlowRemoveReason}
+ * @return gRPC message
+ */
+ public static FlowRuleEnumsProto.FlowRemoveReasonProto translate(FlowRemoveReason flowRemoveReason) {
+
+ switch (flowRemoveReason) {
+ case DELETE:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.DELETE;
+ case EVICTION:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.EVICTION;
+ case GROUP_DELETE:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.GROUP_DELETE;
+ case METER_DELETE:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.METER_DELETE;
+ case HARD_TIMEOUT:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.HARD_TIMEOUT;
+ case IDLE_TIMEOUT:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.IDLE_TIMEOUT;
+ case NO_REASON:
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.NO_REASON;
+ default:
+ log.warn("Unexpected flow remove reason: {}", flowRemoveReason);
+ return FlowRuleEnumsProto.FlowRemoveReasonProto.UNRECOGNIZED;
+ }
+ }
+
+ /**
+ * Translates gRPC FlowRemoveReason to {@link FlowRemoveReason}.
+ *
+ * @param flowRemoveReason gRPC message
+ * @return {@link FlowRemoveReason}
+ */
+ public static Optional<FlowRemoveReason> translate(FlowRuleEnumsProto.FlowRemoveReasonProto flowRemoveReason) {
+
+ switch (flowRemoveReason) {
+ case DELETE:
+ return Optional.of(FlowRemoveReason.DELETE);
+ case EVICTION:
+ return Optional.of(FlowRemoveReason.EVICTION);
+ case GROUP_DELETE:
+ return Optional.of(FlowRemoveReason.GROUP_DELETE);
+ case METER_DELETE:
+ return Optional.of(FlowRemoveReason.METER_DELETE);
+ case HARD_TIMEOUT:
+ return Optional.of(FlowRemoveReason.HARD_TIMEOUT);
+ case IDLE_TIMEOUT:
+ return Optional.of(FlowRemoveReason.IDLE_TIMEOUT);
+ case NO_REASON:
+ return Optional.of(FlowRemoveReason.NO_REASON);
+ default:
+ log.warn("Unexpected flow remove reason: {}", flowRemoveReason);
+ return Optional.empty();
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private FlowRuleEnumsProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java
new file mode 100644
index 0000000..76046e7
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/FlowRuleProtoTranslator.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.flow;
+
+import org.onosproject.grpc.net.flow.models.FlowRuleProtoOuterClass.FlowRuleProto;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.FlowRule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * gRPC FlowRuleProto message to equivalent ONOS FlowRule conversion related utilities.
+ */
+public final class FlowRuleProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(FlowRuleProtoTranslator.class);
+
+ /**
+ * Translates {@link FlowRule} to gRPC FlowRuleProto.
+ *
+ * @param flowRule {@link FlowRule}
+ * @return gRPC message
+ */
+ public static FlowRuleProto translate(FlowRule flowRule) {
+
+ if (flowRule != null) {
+ FlowRuleProto.Builder builder = FlowRuleProto.newBuilder();
+ builder.setAppId(flowRule.appId())
+ .setDeviceId(flowRule.deviceId().toString())
+ .setFlowId(flowRule.id().value())
+ .setPermanent(flowRule.isPermanent())
+ .setPriority(flowRule.priority())
+ .setReason(FlowRuleEnumsProtoTranslator.translate(flowRule.reason()))
+ .setTableId(flowRule.tableId())
+ .setTableName(flowRule.table().toString());
+
+ // TODO: need to set TrafficTreatment and TrafficSelector
+
+ return builder.build();
+ }
+ return FlowRuleProto.getDefaultInstance();
+ }
+
+ /**
+ * Translates gRPC FlowRule to {@link FlowRule}.
+ *
+ * @param flowRule gRPC message
+ * @return {@link FlowRule}
+ */
+ public static FlowRule translate(FlowRuleProto flowRule) {
+
+ if (flowRule.equals(FlowRuleProto.getDefaultInstance())) {
+ return null;
+ }
+
+ DeviceId deviceId = DeviceId.deviceId(flowRule.getDeviceId());
+
+ // TODO: to register AppId need to find a way to get CoreService
+
+ FlowRule.FlowRemoveReason reason =
+ FlowRuleEnumsProtoTranslator.translate(flowRule.getReason()).get();
+
+ FlowRule.Builder resultBuilder = new DefaultFlowRule.Builder();
+ resultBuilder.forDevice(deviceId);
+ resultBuilder.forTable(flowRule.getTableId());
+ resultBuilder.withPriority(flowRule.getPriority());
+ resultBuilder.withCookie(flowRule.getFlowId());
+ resultBuilder.withReason(reason);
+
+ if (flowRule.getPermanent()) {
+ resultBuilder.makePermanent();
+ } else {
+ resultBuilder.makeTemporary(flowRule.getTimeout());
+ }
+
+ // TODO: need to deal with TrafficTreatment and TrafficSelector
+
+ return resultBuilder.build();
+ }
+
+ // Utility class not intended for instantiation.
+ private FlowRuleProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/package-info.java
new file mode 100644
index 0000000..08d0df9
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/flow/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS flow models.
+ */
+package org.onosproject.incubator.protobuf.models.net.flow;
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/link/LinkEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/link/LinkEnumsProtoTranslator.java
new file mode 100644
index 0000000..bc87984
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/link/LinkEnumsProtoTranslator.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.link;
+
+import org.onosproject.grpc.net.link.models.LinkEnumsProto;
+import org.onosproject.net.Link;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC LinkType and LinkState message to equivalent ONOS enum conversion related utilities.
+ */
+public final class LinkEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(LinkEnumsProtoTranslator.class);
+
+ /**
+ * Translates gRPC enum LinkType to Optional of ONOS enum.
+ *
+ * @param type linktype type in gRPC enum
+ * @return Optional of equivalent ONOS enum or empty if not recognized
+ */
+ public static Optional<Link.Type> translate(LinkEnumsProto.LinkTypeProto type) {
+ switch (type) {
+ case DIRECT:
+ return Optional.of(Link.Type.DIRECT);
+ case INDIRECT:
+ return Optional.of(Link.Type.INDIRECT);
+ case EDGE:
+ return Optional.of(Link.Type.EDGE);
+ case TUNNEL:
+ return Optional.of(Link.Type.TUNNEL);
+ case OPTICAL:
+ return Optional.of(Link.Type.OPTICAL);
+ case VIRTUAL:
+ return Optional.of(Link.Type.VIRTUAL);
+ default:
+ log.warn("Unrecognized Type gRPC message: {}", type);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates ONOS enum Type to gRPC enum.
+ *
+ * @param type ONOS' Type type
+ * @return equivalent gRPC message enum
+ */
+ public static LinkEnumsProto.LinkTypeProto translate(Link.Type type) {
+ switch (type) {
+ case DIRECT:
+ return LinkEnumsProto.LinkTypeProto.DIRECT;
+ case INDIRECT:
+ return LinkEnumsProto.LinkTypeProto.INDIRECT;
+ case EDGE:
+ return LinkEnumsProto.LinkTypeProto.EDGE;
+ case TUNNEL:
+ return LinkEnumsProto.LinkTypeProto.TUNNEL;
+ case OPTICAL:
+ return LinkEnumsProto.LinkTypeProto.OPTICAL;
+ case VIRTUAL:
+ return LinkEnumsProto.LinkTypeProto.VIRTUAL;
+ default:
+ log.warn("Unrecognized type", type);
+ throw new IllegalArgumentException("Unrecognized Type");
+ }
+ }
+
+ /**
+ * Translates gRPC enum LinkState to Optional of ONOS enum.
+ *
+ * @param state linkstate state in gRPC enum
+ * @return Optional of equivalent ONOS enum or empty if not recognized
+ */
+ public static Optional<Link.State> translate(LinkEnumsProto.LinkStateProto state) {
+ switch (state) {
+ case ACTIVE:
+ return Optional.of(Link.State.ACTIVE);
+ case INACTIVE:
+ return Optional.of(Link.State.INACTIVE);
+ default:
+ log.warn("Unrecognized State gRPC message: {}", state);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates ONOS enum State to gRPC enum.
+ *
+ * @param state ONOS' state state
+ * @return equivalent gRPC message enum
+ */
+ public static LinkEnumsProto.LinkStateProto translate(Link.State state) {
+ switch (state) {
+ case ACTIVE:
+ return LinkEnumsProto.LinkStateProto.ACTIVE;
+ case INACTIVE:
+ return LinkEnumsProto.LinkStateProto.INACTIVE;
+ default:
+ log.warn("Unrecognized State", state);
+ throw new IllegalArgumentException("Unrecognized State");
+ }
+ }
+
+
+ // Utility class not intended for instantiation.
+ private LinkEnumsProtoTranslator() {}
+
+}
+
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/link/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/link/package-info.java
new file mode 100644
index 0000000..1392669
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/link/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS link models.
+ */
+package org.onosproject.incubator.protobuf.models.net.link;
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java
new file mode 100644
index 0000000..f0825fb
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandEnumsProtoTranslator.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.meter;
+
+import org.onosproject.grpc.net.meter.models.BandEnumsProto;
+import org.onosproject.net.meter.Band;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC message conversion related utilities for band enums.
+ */
+public final class BandEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(BandEnumsProtoTranslator.class);
+
+ /**
+ * Translates gRPC enum Band Type to ONOS enum.
+ *
+ * @param bandType BandType in gRPC enum
+ * @return equivalent in ONOS enum
+ */
+ public static Optional<Band.Type> translate(BandEnumsProto.BandTypeProto bandType) {
+ switch (bandType) {
+ case DROP:
+ return Optional.of(Band.Type.DROP);
+ case REMARK:
+ return Optional.of(Band.Type.REMARK);
+ case EXPERIMENTAL:
+ return Optional.of(Band.Type.EXPERIMENTAL);
+ default:
+ log.warn("Unrecognized BandType gRPC message: {}", bandType);
+ return Optional.empty();
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private BandEnumsProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java
new file mode 100644
index 0000000..ba4460d
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/BandProtoTranslator.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.meter;
+
+import org.onosproject.grpc.net.meter.models.BandEnumsProto;
+import org.onosproject.grpc.net.meter.models.BandProtoOuterClass.BandProto;
+import org.onosproject.net.meter.Band;
+import org.onosproject.net.meter.DefaultBand;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * gRPC message conversion related utilities for band service.
+ */
+public final class BandProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(BandProtoTranslator.class);
+
+ /**
+ * Translates gRPC Band to {@link Band}.
+ *
+ * @param gBand gRPC message
+ * @return {@link Band}
+ */
+ public static Band translate(BandProto gBand) {
+ Band.Type type = BandEnumsProtoTranslator.translate(gBand.getType()).get();
+ long rate = gBand.getRate();
+ long burstSize = gBand.getBurst();
+ short prec = (short) gBand.getDropPrecedence();
+ Band band = new DefaultBand(type, rate, burstSize, prec);
+ return band;
+ }
+
+ /**
+ * Translates gRPC List Bands to Collection Band.
+ *
+ * @param listBands gRPC message
+ * @return Collection Band
+ */
+ public static Collection<Band> translate(List<BandProto> listBands) {
+ Collection<Band> bands = new ArrayList<>();
+ listBands.forEach(d -> bands.add(translate(d)));
+ return bands;
+ }
+
+ /**
+ * Translates ONOS enum Band Type to gRPC enum.
+ *
+ * @param bandType BandType in ONOS enum
+ * @return equivalent in gRPC enum
+ */
+ public static BandEnumsProto.BandTypeProto translate(Band.Type bandType) {
+ switch (bandType) {
+ case DROP:
+ return BandEnumsProto.BandTypeProto.DROP;
+ case REMARK:
+ return BandEnumsProto.BandTypeProto.REMARK;
+ case EXPERIMENTAL:
+ return BandEnumsProto.BandTypeProto.EXPERIMENTAL;
+ default:
+ log.warn("Unrecognized BandType ONOS message: {}", bandType);
+ return BandEnumsProto.BandTypeProto.UNRECOGNIZED;
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private BandProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java
new file mode 100644
index 0000000..b73117c
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterEnumsProtoTranslator.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.meter;
+
+import org.onosproject.grpc.net.meter.models.MeterEnumsProto;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC message conversion related utilities for meter enums.
+ */
+public final class MeterEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(MeterEnumsProtoTranslator.class);
+
+ /**
+ * Translates gRPC enum MeterUnit to ONOS enum.
+ *
+ * @param unit meterUnit in gRPC enum
+ * @return equivalent in ONOS enum
+ */
+ public static Optional<Meter.Unit> translate(MeterEnumsProto.MeterUnitProto unit) {
+ switch (unit) {
+ case PKTS_PER_SEC:
+ return Optional.of(Meter.Unit.PKTS_PER_SEC);
+ case KB_PER_SEC:
+ return Optional.of(Meter.Unit.KB_PER_SEC);
+ default:
+ log.warn("Unrecognized MeterUnit gRPC message: {}", unit);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates ONOS enum Meter.Unit Type to gRPC enum.
+ *
+ * @param unit Meter.Unit in ONOS enum
+ * @return equivalent in gRPC enum
+ */
+ public static MeterEnumsProto.MeterUnitProto translate(Meter.Unit unit) {
+ switch (unit) {
+ case PKTS_PER_SEC:
+ return MeterEnumsProto.MeterUnitProto.PKTS_PER_SEC;
+ case KB_PER_SEC:
+ return MeterEnumsProto.MeterUnitProto.KB_PER_SEC;
+ default:
+ log.warn("Unrecognized MeterUnit ONOS message: {}", unit);
+ return MeterEnumsProto.MeterUnitProto.UNRECOGNIZED;
+ }
+ }
+
+ /**
+ * Translates ONOS enum MeterState Type to gRPC enum.
+ *
+ * @param meterState MeterState in ONOS enum
+ * @return equivalent in gRPC enum
+ */
+ public static MeterEnumsProto.MeterStateProto translate(MeterState meterState) {
+ switch (meterState) {
+ case PENDING_ADD:
+ return MeterEnumsProto.MeterStateProto.PENDING_ADD;
+ case ADDED:
+ return MeterEnumsProto.MeterStateProto.ADDED;
+ case PENDING_REMOVE:
+ return MeterEnumsProto.MeterStateProto.PENDING_REMOVE;
+ case REMOVED:
+ return MeterEnumsProto.MeterStateProto.REMOVED;
+ default:
+ log.warn("Unrecognized MeterState ONOS message: {}", meterState);
+ return MeterEnumsProto.MeterStateProto.UNRECOGNIZED;
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private MeterEnumsProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterProtoTranslator.java
new file mode 100644
index 0000000..1044664
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterProtoTranslator.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.meter;
+
+import com.google.common.annotations.Beta;
+import org.onosproject.grpc.net.meter.models.BandProtoOuterClass.BandProto;
+import org.onosproject.grpc.net.meter.models.MeterProtoOuterClass.MeterProto;
+import org.onosproject.incubator.protobuf.models.core.ApplicationIdProtoTranslator;
+import org.onosproject.net.meter.Meter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.stream.Collectors;
+
+/**
+ * gRPC message conversion related utilities for meter service.
+ */
+@Beta
+public final class MeterProtoTranslator {
+ private static final Logger log = LoggerFactory.getLogger(MeterProtoTranslator.class);
+
+ /**
+ * Translates {@link Meter} to gRPC MeterCore message.
+ *
+ * @param meter {@link Meter}
+ * @return gRPC MeterCore message
+ */
+ public static MeterProto translate(Meter meter) {
+ return MeterProto.newBuilder()
+ .setDeviceId(meter.deviceId().toString())
+ .setApplicationId(ApplicationIdProtoTranslator.translate(meter.appId()))
+ .setUnit(MeterEnumsProtoTranslator.translate(meter.unit()))
+ .setIsBurst(meter.isBurst())
+ .addAllBands(meter.bands().stream()
+ .map(b -> BandProto.newBuilder()
+ .setRate(b.rate())
+ .setBurst(b.burst())
+ .setDropPrecedence(b.dropPrecedence())
+ .setType(BandProtoTranslator.translate(b.type()))
+ .setPackets(b.packets())
+ .setBytes(b.bytes())
+ .build())
+ .collect(Collectors.toList()))
+ .setState(MeterEnumsProtoTranslator.translate(meter.state()))
+ .setLife(meter.life())
+ .setReferenceCount(meter.referenceCount())
+ .setPacketsSeen(meter.packetsSeen())
+ .setBytesSeen(meter.bytesSeen())
+ .build();
+ }
+
+ // Utility class not intended for instantiation.
+ private MeterProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java
new file mode 100644
index 0000000..dd6c5fb
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/MeterRequestProtoTranslator.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.meter;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.grpc.net.meter.models.MeterEnumsProto;
+import org.onosproject.grpc.net.meter.models.MeterRequestProtoOuterClass;
+import org.onosproject.incubator.protobuf.models.core.ApplicationIdProtoTranslator;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.meter.Band;
+import org.onosproject.net.meter.DefaultMeterRequest;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Optional;
+
+/**
+ * gRPC message conversion related utilities for meter request service.
+ */
+public final class MeterRequestProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(MeterRequestProtoTranslator.class);
+
+ /**
+ * Translates gRPC MeterRequestType to {@link MeterRequest.Type}.
+ *
+ * @param type gRPC message
+ * @return {@link MeterRequest.Type}
+ */
+ public static Optional<Object> translate(MeterEnumsProto.MeterRequestTypeProto type) {
+ switch (type) {
+ case ADD:
+ return Optional.of(MeterRequest.Type.ADD);
+ case MODIFY:
+ return Optional.of(MeterRequest.Type.MODIFY);
+ case REMOVE:
+ return Optional.of(MeterRequest.Type.REMOVE);
+ default:
+ log.warn("Unrecognized MeterRequest type gRPC message: {}", type);
+ return Optional.empty();
+ }
+ }
+
+ /**
+ * Translates gRPC MeterRequest to {@link MeterRequest}.
+ *
+ * @param meterRequest gRPC message
+ * @return {@link MeterRequest}
+ */
+ public static MeterRequest translate(MeterRequestProtoOuterClass.MeterRequestProto meterRequest) {
+
+ DeviceId deviceid = DeviceId.deviceId(meterRequest.getDeviceId());
+ ApplicationId appId = ApplicationIdProtoTranslator.translate(meterRequest.getApplicationId());
+ Meter.Unit unit = MeterEnumsProtoTranslator.translate(meterRequest.getUnit()).get();
+ boolean burst = meterRequest.getIsBurst();
+ Collection<Band> bands = BandProtoTranslator.translate(meterRequest.getBandsList());
+ MeterRequest.Type type = (MeterRequest.Type) translate(meterRequest.getType()).get();
+ if (type == MeterRequest.Type.ADD) {
+ return DefaultMeterRequest.builder()
+ .forDevice(deviceid)
+ .fromApp(appId)
+ .withUnit(unit)
+ .withBands(bands)
+ .add();
+ } else {
+ return DefaultMeterRequest.builder()
+ .forDevice(deviceid)
+ .fromApp(appId)
+ .withUnit(unit)
+ .withBands(bands)
+ .remove();
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private MeterRequestProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/package-info.java
new file mode 100644
index 0000000..a90c429
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/meter/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS meter models.
+ */
+package org.onosproject.incubator.protobuf.models.net.meter;
\ No newline at end of file
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/package-info.java
new file mode 100644
index 0000000..e393681
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS network models.
+ */
+package org.onosproject.incubator.protobuf.models.net;
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/region/RegionEnumsProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/region/RegionEnumsProtoTranslator.java
new file mode 100644
index 0000000..6f3130f
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/region/RegionEnumsProtoTranslator.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.net.region;
+
+import org.onosproject.grpc.net.region.models.RegionEnumsProto;
+import org.onosproject.net.region.Region;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+/**
+ * gRPC RegionType message to equivalent ONOS enum conversion related utilities.
+ */
+public final class RegionEnumsProtoTranslator {
+
+ private static final Logger log = LoggerFactory.getLogger(RegionEnumsProtoTranslator.class);
+
+ /**
+ * Translates gRPC enum RegionType to Optional of ONOS enum.
+ *
+ * @param type regiontype type in gRPC enum
+ * @return Optional of equivalent ONOS enum or empty if not recognized
+ */
+ public static Optional<Region.Type> translate(RegionEnumsProto.RegionTypeProto type) {
+ switch (type) {
+ case CONTINENT:
+ return Optional.of(Region.Type.CONTINENT);
+ case COUNTRY:
+ return Optional.of(Region.Type.COUNTRY);
+ case METRO:
+ return Optional.of(Region.Type.METRO);
+ case CAMPUS:
+ return Optional.of(Region.Type.CAMPUS);
+ case BUILDING:
+ return Optional.of(Region.Type.BUILDING);
+ case DATA_CENTER:
+ return Optional.of(Region.Type.DATA_CENTER);
+ case FLOOR:
+ return Optional.of(Region.Type.FLOOR);
+ case ROOM:
+ return Optional.of(Region.Type.ROOM);
+ case RACK:
+ return Optional.of(Region.Type.RACK);
+ case LOGICAL_GROUP:
+ return Optional.of(Region.Type.LOGICAL_GROUP);
+ default:
+ log.warn("Unrecognized Type gRPC message: {}", type);
+ return Optional.empty();
+ }
+ }
+
+
+ /**
+ * Translates ONOS enum regionType to gRPC enum regionType.
+ *
+ * @param type ONOS' Type type
+ * @return equivalent gRPC message enum
+ */
+ public static RegionEnumsProto.RegionTypeProto translate(Region.Type type) {
+ switch (type) {
+ case CONTINENT:
+ return RegionEnumsProto.RegionTypeProto.CONTINENT;
+ case COUNTRY:
+ return RegionEnumsProto.RegionTypeProto.COUNTRY;
+ case METRO:
+ return RegionEnumsProto.RegionTypeProto.METRO;
+ case CAMPUS:
+ return RegionEnumsProto.RegionTypeProto.CAMPUS;
+ case BUILDING:
+ return RegionEnumsProto.RegionTypeProto.BUILDING;
+ case DATA_CENTER:
+ return RegionEnumsProto.RegionTypeProto.DATA_CENTER;
+ case FLOOR:
+ return RegionEnumsProto.RegionTypeProto.FLOOR;
+ case ROOM:
+ return RegionEnumsProto.RegionTypeProto.ROOM;
+ case RACK:
+ return RegionEnumsProto.RegionTypeProto.RACK;
+ case LOGICAL_GROUP:
+ return RegionEnumsProto.RegionTypeProto.LOGICAL_GROUP;
+ default:
+ log.warn("Unrecognized type", type);
+ throw new IllegalArgumentException("Unrecognized Type");
+ }
+ }
+
+ // Utility class not intended for instantiation.
+ private RegionEnumsProtoTranslator() {}
+}
+
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/region/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/region/package-info.java
new file mode 100644
index 0000000..459ad32
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/net/region/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS region models.
+ */
+package org.onosproject.incubator.protobuf.models.net.region;
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/security/PermissionProtoTranslator.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/security/PermissionProtoTranslator.java
new file mode 100644
index 0000000..d3cdc7d
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/security/PermissionProtoTranslator.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.incubator.protobuf.models.security;
+
+import org.onosproject.grpc.security.models.PermissionProtoOuterClass.PermissionProto;
+import org.onosproject.security.Permission;
+
+import static org.onosproject.grpc.security.models.PermissionProtoOuterClass.PermissionProto.getDefaultInstance;
+
+/**
+ * gRPC Permission message to equivalent ONOS Permission conversion related utilities.
+ */
+public final class PermissionProtoTranslator {
+
+ /**
+ * Translate {@link Permission} to gRPC permission message.
+ *
+ * @param permission {@link Permission}
+ * @return gRPC message
+ */
+ public static PermissionProto translate(Permission permission) {
+
+ if (permission != null) {
+ return PermissionProto.newBuilder()
+ .setActions(permission.getActions())
+ .setClassname(permission.getClassName())
+ .setName(permission.getName())
+ .build();
+ }
+
+ return getDefaultInstance();
+ }
+
+ /**
+ * Translate gRPC permission message to {@link Permission}.
+ *
+ * @param permission gRPC message
+ * @return {@link Permission}
+ */
+ public static Permission translate(PermissionProto permission) {
+
+ return new Permission(permission.getClassname(),
+ permission.getName(), permission.getActions());
+ }
+
+ // Utility class not intended for instantiation.
+ private PermissionProtoTranslator() {}
+}
diff --git a/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/security/package-info.java b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/security/package-info.java
new file mode 100644
index 0000000..5ee50f4
--- /dev/null
+++ b/core/protobuf/models/src/main/java/org/onosproject/incubator/protobuf/models/security/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * Utilities to handle ProtoBuf version of ONOS security models.
+ */
+package org.onosproject.incubator.protobuf.models.security;
\ No newline at end of file
diff --git a/core/store/dist/BUILD b/core/store/dist/BUILD
index 98eefbb..e3e702c 100644
--- a/core/store/dist/BUILD
+++ b/core/store/dist/BUILD
@@ -9,7 +9,6 @@
"@io_netty_netty_transport_native_unix_common//jar",
"@io_netty_netty_resolver//jar",
"@commons_math3//jar",
- "//incubator/api:onos-incubator-api",
]
TEST_DEPS = TEST + [
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
index bddb7a0..9a0584a 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
@@ -23,8 +23,6 @@
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
-import org.onosproject.incubator.net.virtual.NetworkId;
-import org.onosproject.incubator.net.virtual.VirtualNetworkIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentData;
import org.onosproject.net.intent.IntentEvent;
@@ -68,6 +66,7 @@
import static org.onosproject.store.OsgiPropertyConstants.GIS_PERSISTENCE_ENABLED;
import static org.onosproject.store.OsgiPropertyConstants.GIS_PERSISTENCE_ENABLED_DEFAULT;
import static org.slf4j.LoggerFactory.getLogger;
+
/**
* Manages inventory of Intents in a distributed data store that uses optimistic
* replication and gossip based techniques.
@@ -158,8 +157,6 @@
KryoNamespace.Builder intentSerializer = KryoNamespace.newBuilder()
.register(KryoNamespaces.API)
.register(IntentData.class)
- .register(VirtualNetworkIntent.class)
- .register(NetworkId.class)
.register(MultiValuedTimestamp.class);
EventuallyConsistentMapBuilder currentECMapBuilder =
diff --git a/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java
new file mode 100644
index 0000000..09a55ad
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/DistributedMeterStore.java
@@ -0,0 +1,500 @@
+/*
+ * Copyright 2015-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.meter.impl;
+
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.commons.lang.math.RandomUtils;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.MeterQuery;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverService;
+import org.onosproject.net.meter.Band;
+import org.onosproject.net.meter.DefaultBand;
+import org.onosproject.net.meter.DefaultMeter;
+import org.onosproject.net.meter.DefaultMeterFeatures;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterEvent;
+import org.onosproject.net.meter.MeterFailReason;
+import org.onosproject.net.meter.MeterFeatures;
+import org.onosproject.net.meter.MeterFeaturesFlag;
+import org.onosproject.net.meter.MeterFeaturesKey;
+import org.onosproject.net.meter.MeterId;
+import org.onosproject.net.meter.MeterKey;
+import org.onosproject.net.meter.MeterOperation;
+import org.onosproject.net.meter.MeterState;
+import org.onosproject.net.meter.MeterStore;
+import org.onosproject.net.meter.MeterStoreDelegate;
+import org.onosproject.net.meter.MeterStoreResult;
+import org.onosproject.store.AbstractStore;
+import org.onosproject.store.primitives.DefaultDistributedSet;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.AtomicCounterMap;
+import org.onosproject.store.service.ConsistentMap;
+import org.onosproject.store.service.DistributedPrimitive;
+import org.onosproject.store.service.DistributedSet;
+import org.onosproject.store.service.MapEvent;
+import org.onosproject.store.service.MapEventListener;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageException;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.Versioned;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+import static org.onosproject.store.meter.impl.DistributedMeterStore.ReuseStrategy.FIRST_FIT;
+import static org.onosproject.net.meter.MeterFailReason.TIMEOUT;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * A distributed meter store implementation. Meters are stored consistently
+ * across the cluster.
+ */
+@Component(immediate = true, service = MeterStore.class)
+public class DistributedMeterStore extends AbstractStore<MeterEvent, MeterStoreDelegate>
+ implements MeterStore {
+
+ private Logger log = getLogger(getClass());
+
+ private static final String METERSTORE = "onos-meter-store";
+ private static final String METERFEATURESSTORE = "onos-meter-features-store";
+ private static final String AVAILABLEMETERIDSTORE = "onos-meters-available-store";
+ private static final String METERIDSTORE = "onos-meters-id-store";
+
+ private static final KryoNamespace.Builder APP_KRYO_BUILDER = KryoNamespace.newBuilder()
+ .register(KryoNamespaces.API)
+ .register(MeterKey.class)
+ .register(MeterData.class)
+ .register(DefaultMeter.class)
+ .register(DefaultBand.class)
+ .register(Band.Type.class)
+ .register(MeterState.class)
+ .register(Meter.Unit.class);
+
+ private Serializer serializer = Serializer.using(Lists.newArrayList(APP_KRYO_BUILDER.build()));
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ private StorageService storageService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ private MastershipService mastershipService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ private ClusterService clusterService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ protected DriverService driverService;
+
+ private ConsistentMap<MeterKey, MeterData> meters;
+ private NodeId local;
+
+ private ConsistentMap<MeterFeaturesKey, MeterFeatures> meterFeatures;
+
+ private MapEventListener<MeterKey, MeterData> mapListener = new InternalMapEventListener();
+
+ private Map<MeterKey, CompletableFuture<MeterStoreResult>> futures =
+ Maps.newConcurrentMap();
+
+ // Available meter identifiers
+ private DistributedSet<MeterKey> availableMeterIds;
+
+ // Atomic counter map for generation of new identifiers;
+ private AtomicCounterMap<DeviceId> meterIdGenerators;
+
+ /**
+ * Defines possible selection strategies to reuse meter ids.
+ */
+ enum ReuseStrategy {
+ /**
+ * Select randomly an available id.
+ */
+ RANDOM,
+ /**
+ * Select the first one.
+ */
+ FIRST_FIT
+ }
+
+ private ReuseStrategy reuseStrategy = FIRST_FIT;
+
+ @Activate
+ public void activate() {
+ local = clusterService.getLocalNode().id();
+
+ meters = storageService.<MeterKey, MeterData>consistentMapBuilder()
+ .withName(METERSTORE)
+ .withSerializer(serializer).build();
+
+ meters.addListener(mapListener);
+
+ meterFeatures = storageService.<MeterFeaturesKey, MeterFeatures>consistentMapBuilder()
+ .withName(METERFEATURESSTORE)
+ .withSerializer(Serializer.using(KryoNamespaces.API,
+ MeterFeaturesKey.class,
+ MeterFeatures.class,
+ DefaultMeterFeatures.class,
+ Band.Type.class,
+ Meter.Unit.class,
+ MeterFailReason.class,
+ MeterFeaturesFlag.class)).build();
+
+ // Init the set of the available ids
+ availableMeterIds = new DefaultDistributedSet<>(storageService.<MeterKey>setBuilder()
+ .withName(AVAILABLEMETERIDSTORE)
+ .withSerializer(Serializer.using(KryoNamespaces.API,
+ MeterKey.class)).build(),
+ DistributedPrimitive.DEFAULT_OPERATION_TIMEOUT_MILLIS);
+
+ // Init atomic map counters
+ meterIdGenerators = storageService.<DeviceId>atomicCounterMapBuilder()
+ .withName(METERIDSTORE)
+ .withSerializer(Serializer.using(KryoNamespaces.API)).build();
+
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ meters.removeListener(mapListener);
+ log.info("Stopped");
+ }
+
+ @Override
+ public CompletableFuture<MeterStoreResult> storeMeter(Meter meter) {
+ // Init steps
+ CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ // Store the future related to the operation
+ futures.put(key, future);
+ // Store the meter data
+ MeterData data = new MeterData(meter, null, local);
+ try {
+ meters.put(key, data);
+ } catch (StorageException e) {
+ futures.remove(key);
+ future.completeExceptionally(e);
+ }
+ // Done, return the future
+ return future;
+ }
+
+ @Override
+ public CompletableFuture<MeterStoreResult> deleteMeter(Meter meter) {
+ // Init steps
+ CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ // Store the future related to the operation
+ futures.put(key, future);
+ // Create the meter data
+ MeterData data = new MeterData(meter, null, local);
+ // Update the state of the meter. It will be pruned by observing
+ // that it has been removed from the dataplane.
+ try {
+ // If it does not exist in the system
+ if (meters.computeIfPresent(key, (k, v) -> data) == null) {
+ // Complete immediately
+ future.complete(MeterStoreResult.success());
+ }
+ } catch (StorageException e) {
+ futures.remove(key);
+ future.completeExceptionally(e);
+ }
+ // Done, return the future
+ return future;
+ }
+
+ @Override
+ public MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures) {
+ MeterStoreResult result = MeterStoreResult.success();
+ MeterFeaturesKey key = MeterFeaturesKey.key(meterfeatures.deviceId());
+ try {
+ meterFeatures.putIfAbsent(key, meterfeatures);
+ } catch (StorageException e) {
+ result = MeterStoreResult.fail(TIMEOUT);
+ }
+ return result;
+ }
+
+ @Override
+ public MeterStoreResult deleteMeterFeatures(DeviceId deviceId) {
+ MeterStoreResult result = MeterStoreResult.success();
+ MeterFeaturesKey key = MeterFeaturesKey.key(deviceId);
+ try {
+ meterFeatures.remove(key);
+ } catch (StorageException e) {
+ result = MeterStoreResult.fail(TIMEOUT);
+ }
+ return result;
+ }
+
+ @Override
+ public CompletableFuture<MeterStoreResult> updateMeter(Meter meter) {
+ CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ futures.put(key, future);
+
+ MeterData data = new MeterData(meter, null, local);
+ try {
+ if (meters.computeIfPresent(key, (k, v) -> data) == null) {
+ future.complete(MeterStoreResult.fail(MeterFailReason.INVALID_METER));
+ }
+ } catch (StorageException e) {
+ futures.remove(key);
+ future.completeExceptionally(e);
+ }
+ return future;
+ }
+
+ @Override
+ public void updateMeterState(Meter meter) {
+ MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
+ meters.computeIfPresent(key, (k, v) -> {
+ DefaultMeter m = (DefaultMeter) v.meter();
+ m.setState(meter.state());
+ m.setProcessedPackets(meter.packetsSeen());
+ m.setProcessedBytes(meter.bytesSeen());
+ m.setLife(meter.life());
+ // TODO: Prune if drops to zero.
+ m.setReferenceCount(meter.referenceCount());
+ return new MeterData(m, null, v.origin());
+ });
+ }
+
+ @Override
+ public Meter getMeter(MeterKey key) {
+ MeterData data = Versioned.valueOrElse(meters.get(key), null);
+ return data == null ? null : data.meter();
+ }
+
+ @Override
+ public Collection<Meter> getAllMeters() {
+ return Collections2.transform(meters.asJavaMap().values(),
+ MeterData::meter);
+ }
+
+ @Override
+ public Collection<Meter> getAllMeters(DeviceId deviceId) {
+ return Collections2.transform(
+ Collections2.filter(meters.asJavaMap().values(),
+ (MeterData m) -> m.meter().deviceId().equals(deviceId)),
+ MeterData::meter);
+ }
+
+ @Override
+ public void failedMeter(MeterOperation op, MeterFailReason reason) {
+ MeterKey key = MeterKey.key(op.meter().deviceId(), op.meter().id());
+ meters.computeIfPresent(key, (k, v) ->
+ new MeterData(v.meter(), reason, v.origin()));
+ }
+
+ @Override
+ public void deleteMeterNow(Meter m) {
+ // Create the key
+ MeterKey key = MeterKey.key(m.deviceId(), m.id());
+ // Remove the future
+ futures.remove(key);
+ // Remove the meter
+ meters.remove(key);
+ // Free the id
+ freeMeterId(m.deviceId(), m.id());
+ // Finally notify the delegate
+ notifyDelegate(new MeterEvent(MeterEvent.Type.METER_REMOVED, m));
+ }
+
+ @Override
+ public long getMaxMeters(MeterFeaturesKey key) {
+ MeterFeatures features = Versioned.valueOrElse(meterFeatures.get(key), null);
+ return features == null ? 0L : features.maxMeter();
+ }
+
+ // queryMaxMeters is implemented in FullMetersAvailable behaviour.
+ private long queryMaxMeters(DeviceId device) {
+ // Get driver handler for this device
+ DriverHandler handler = driverService.createHandler(device);
+ // If creation failed or the device does not have this behavior
+ if (handler == null || !handler.hasBehaviour(MeterQuery.class)) {
+ // We cannot know max meter
+ return 0L;
+ }
+ // Get the behavior
+ MeterQuery query = handler.behaviour(MeterQuery.class);
+ // Return as max meter the result of the query
+ return query.getMaxMeters();
+ }
+
+ private boolean updateMeterIdAvailability(DeviceId deviceId, MeterId id,
+ boolean available) {
+ // According to available, make available or unavailable a meter key
+ return available ? availableMeterIds.add(MeterKey.key(deviceId, id)) :
+ availableMeterIds.remove(MeterKey.key(deviceId, id));
+ }
+
+ private MeterId getNextAvailableId(Set<MeterId> availableIds) {
+ // If there are no available ids
+ if (availableIds.isEmpty()) {
+ // Just end the cycle
+ return null;
+ }
+ // If it is the first fit
+ if (reuseStrategy == FIRST_FIT || availableIds.size() == 1) {
+ return availableIds.iterator().next();
+ }
+ // If it is random, get the size
+ int size = availableIds.size();
+ // Return a random element
+ return Iterables.get(availableIds, RandomUtils.nextInt(size));
+ }
+
+ // Implements reuse strategy
+ private MeterId firstReusableMeterId(DeviceId deviceId) {
+ // Filter key related to device id, and reduce to meter ids
+ Set<MeterId> localAvailableMeterIds = availableMeterIds.stream()
+ .filter(meterKey -> meterKey.deviceId().equals(deviceId))
+ .map(MeterKey::meterId)
+ .collect(Collectors.toSet());
+ // Get next available id
+ MeterId meterId = getNextAvailableId(localAvailableMeterIds);
+ // Iterate until there are items
+ while (meterId != null) {
+ // If we are able to reserve the id
+ if (updateMeterIdAvailability(deviceId, meterId, false)) {
+ // Just end
+ return meterId;
+ }
+ // Update the set
+ localAvailableMeterIds.remove(meterId);
+ // Try another time
+ meterId = getNextAvailableId(localAvailableMeterIds);
+ }
+ // No reusable ids
+ return null;
+ }
+
+ @Override
+ public MeterId allocateMeterId(DeviceId deviceId) {
+ // Init steps
+ MeterId meterId;
+ long id;
+ // Try to reuse meter id
+ meterId = firstReusableMeterId(deviceId);
+ // We found a reusable id, return
+ if (meterId != null) {
+ return meterId;
+ }
+ // If there was no reusable MeterId we have to generate a new value
+ // using maxMeters as upper limit.
+ long maxMeters = getMaxMeters(MeterFeaturesKey.key(deviceId));
+ // If the device does not give us MeterFeatures
+ if (maxMeters == 0L) {
+ // MeterFeatures couldn't be retrieved, fallback to queryMeters.
+ maxMeters = queryMaxMeters(deviceId);
+ }
+ // If we don't know the max, cannot proceed
+ if (maxMeters == 0L) {
+ return null;
+ }
+ // Get a new value
+ id = meterIdGenerators.incrementAndGet(deviceId);
+ // Check with the max, and if the value is bigger, cannot proceed
+ if (id >= maxMeters) {
+ return null;
+ }
+ // Done, return the value
+ return MeterId.meterId(id);
+ }
+
+ @Override
+ public void freeMeterId(DeviceId deviceId, MeterId meterId) {
+ // Avoid to free meter not allocated
+ if (meterIdGenerators.get(deviceId) < meterId.id()) {
+ return;
+ }
+ // Update the availability
+ updateMeterIdAvailability(deviceId, meterId, true);
+ }
+
+ private class InternalMapEventListener implements MapEventListener<MeterKey, MeterData> {
+ @Override
+ public void event(MapEvent<MeterKey, MeterData> event) {
+ MeterKey key = event.key();
+ Versioned<MeterData> value = event.type() == MapEvent.Type.REMOVE ? event.oldValue() : event.newValue();
+ MeterData data = value.value();
+ NodeId master = mastershipService.getMasterFor(data.meter().deviceId());
+ switch (event.type()) {
+ case INSERT:
+ case UPDATE:
+ switch (data.meter().state()) {
+ case PENDING_ADD:
+ case PENDING_REMOVE:
+ if (!data.reason().isPresent() && local.equals(master)) {
+ notifyDelegate(
+ new MeterEvent(data.meter().state() == MeterState.PENDING_ADD ?
+ MeterEvent.Type.METER_ADD_REQ : MeterEvent.Type.METER_REM_REQ,
+ data.meter()));
+ } else if (data.reason().isPresent() && local.equals(data.origin())) {
+ MeterStoreResult msr = MeterStoreResult.fail(data.reason().get());
+ //TODO: No future -> no friend
+ futures.get(key).complete(msr);
+ }
+ break;
+ case ADDED:
+ if (local.equals(data.origin()) &&
+ (data.meter().state() == MeterState.PENDING_ADD
+ || data.meter().state() == MeterState.ADDED)) {
+ futures.computeIfPresent(key, (k, v) -> {
+ notifyDelegate(
+ new MeterEvent(MeterEvent.Type.METER_ADDED, data.meter()));
+ return null;
+ });
+ }
+ break;
+ case REMOVED:
+ if (local.equals(data.origin()) && data.meter().state() == MeterState.PENDING_REMOVE) {
+ futures.remove(key).complete(MeterStoreResult.success());
+ }
+ break;
+ default:
+ log.warn("Unknown meter state type {}", data.meter().state());
+ }
+ break;
+ case REMOVE:
+ //Only happens at origin so we do not need to care.
+ break;
+ default:
+ log.warn("Unknown Map event type {}", event.type());
+ }
+
+ }
+ }
+
+
+}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/meter/impl/MeterData.java b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/MeterData.java
new file mode 100644
index 0000000..8f87c2c
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/MeterData.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2015-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.meter.impl;
+
+import org.onosproject.cluster.NodeId;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterFailReason;
+
+import java.util.Optional;
+
+/**
+ * A class representing the meter information stored in the meter store.
+ */
+public class MeterData {
+
+ private final Meter meter;
+ private final Optional<MeterFailReason> reason;
+ private final NodeId origin;
+
+ public MeterData(Meter meter, MeterFailReason reason, NodeId origin) {
+ this.meter = meter;
+ this.reason = Optional.ofNullable(reason);
+ this.origin = origin;
+ }
+
+ public Meter meter() {
+ return meter;
+ }
+
+ public Optional<MeterFailReason> reason() {
+ return this.reason;
+ }
+
+ public NodeId origin() {
+ return this.origin;
+ }
+
+
+}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/meter/impl/package-info.java b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/package-info.java
new file mode 100644
index 0000000..bfd490b
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onosproject/store/meter/impl/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2015-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A distributed meter store implementation that stores meter data consistently
+ * across the cluster.
+ */
+package org.onosproject.store.meter.impl;
diff --git a/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java
new file mode 100644
index 0000000..5005787
--- /dev/null
+++ b/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java
@@ -0,0 +1,502 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.store.meter.impl;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onlab.packet.IpAddress;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.TestApplicationId;
+import org.onosproject.cluster.ClusterServiceAdapter;
+import org.onosproject.cluster.ControllerNode;
+import org.onosproject.cluster.DefaultControllerNode;
+import org.onosproject.cluster.NodeId;
+import org.onosproject.mastership.MastershipServiceAdapter;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.MeterQuery;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.driver.Driver;
+import org.onosproject.net.driver.DriverData;
+import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.driver.DriverServiceAdapter;
+import org.onosproject.net.meter.Band;
+import org.onosproject.net.meter.DefaultBand;
+import org.onosproject.net.meter.DefaultMeter;
+import org.onosproject.net.meter.DefaultMeterFeatures;
+import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterFeatures;
+import org.onosproject.net.meter.MeterFeaturesKey;
+import org.onosproject.net.meter.MeterId;
+import org.onosproject.net.meter.MeterKey;
+import org.onosproject.net.meter.MeterState;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.TestStorageService;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.*;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.did;
+
+/**
+ * Meter store tests.
+ */
+public class DistributedMeterStoreTest {
+
+ // Test node id
+ private static final NodeId NID_LOCAL = new NodeId("local");
+
+ // Test ip address
+ private static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1");
+
+ // Store under testing
+ private DistributedMeterStore meterStore;
+
+ // Device ids used during the tests
+ private DeviceId did1 = did("1");
+ private DeviceId did2 = did("2");
+ private DeviceId did3 = did("3");
+ private DeviceId did4 = did("4");
+
+ // Meter ids used during the tests
+ private MeterId mid1 = MeterId.meterId(1);
+ private MeterId mid2 = MeterId.meterId(2);
+ private MeterId mid10 = MeterId.meterId(10);
+
+ // Bands used during the tests
+ private Band b1 = DefaultBand.builder()
+ .ofType(Band.Type.DROP)
+ .withRate(500)
+ .build();
+
+ // Meters used during the tests
+ private Meter m1 = DefaultMeter.builder()
+ .forDevice(did1)
+ .fromApp(APP_ID)
+ .withId(mid1)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(Collections.singletonList(b1))
+ .build();
+
+ // Meter features used during the tests
+ private MeterFeatures mef1 = DefaultMeterFeatures.builder().forDevice(did1)
+ .withMaxMeters(3L)
+ .withBandTypes(new HashSet<>())
+ .withUnits(new HashSet<>())
+ .hasStats(false)
+ .hasBurst(false)
+ .withMaxBands((byte) 0)
+ .withMaxColors((byte) 0)
+ .build();
+ private MeterFeatures mef2 = DefaultMeterFeatures.builder().forDevice(did2)
+ .withMaxMeters(10L)
+ .withBandTypes(new HashSet<>())
+ .withUnits(new HashSet<>())
+ .hasStats(false)
+ .hasBurst(false)
+ .withMaxBands((byte) 0)
+ .withMaxColors((byte) 0)
+ .build();
+
+ @Before
+ public void setup() {
+ // Init step
+ meterStore = new DistributedMeterStore();
+ // Let's initialize some internal services
+ TestUtils.setField(meterStore, "storageService", new TestStorageService());
+ TestUtils.setField(meterStore, "clusterService", new TestClusterService());
+ TestUtils.setField(meterStore, "mastershipService", new TestMastershipService());
+ TestUtils.setField(meterStore, "driverService", new TestDriverService());
+
+ // Inject TestApplicationId into the DistributedMeterStore serializer
+ KryoNamespace.Builder testKryoBuilder = TestUtils.getField(meterStore, "APP_KRYO_BUILDER");
+ testKryoBuilder.register(TestApplicationId.class);
+ Serializer testSerializer = Serializer.using(Lists.newArrayList(testKryoBuilder.build()));
+ TestUtils.setField(meterStore, "serializer", testSerializer);
+
+ // Activate the store
+ meterStore.activate();
+ }
+
+ @After
+ public void tearDown() {
+ // Deactivate the store
+ meterStore.deactivate();
+ }
+
+ private void initMeterStore() {
+ // Let's store feature for device 1
+ meterStore.storeMeterFeatures(mef1);
+ // Let's store feature for device 2
+ meterStore.storeMeterFeatures(mef2);
+ }
+
+ /**
+ * Test proper store of meter features.
+ */
+ @Test
+ public void testStoreMeterFeatures() {
+ // Let's store feature for device 1
+ meterStore.storeMeterFeatures(mef1);
+ // Verify store meter features
+ assertThat(meterStore.getMaxMeters(MeterFeaturesKey.key(did1)), is(3L));
+ // Let's store feature for device 1
+ meterStore.storeMeterFeatures(mef2);
+ // Verify store meter features
+ assertThat(meterStore.getMaxMeters(MeterFeaturesKey.key(did2)), is(10L));
+ }
+
+ /**
+ * Test proper delete of meter features.
+ */
+ @Test
+ public void testDeleteMeterFeatures() {
+ // Let's store feature for device 1
+ meterStore.storeMeterFeatures(mef1);
+ // Verify store meter features
+ assertThat(meterStore.getMaxMeters(MeterFeaturesKey.key(did1)), is(3L));
+ // Let's delete the features
+ meterStore.deleteMeterFeatures(did1);
+ // Verify delete meter features
+ assertThat(meterStore.getMaxMeters(MeterFeaturesKey.key(did1)), is(0L));
+ }
+
+ /**
+ * Test proper allocation of meter ids.
+ */
+ @Test
+ public void testAllocateId() {
+ // Init the store
+ initMeterStore();
+ // Allocate a meter id and verify is equal to mid1
+ assertThat(mid1, is(meterStore.allocateMeterId(did1)));
+ // Allocate a meter id and verify is equal to mid2
+ assertThat(mid2, is(meterStore.allocateMeterId(did1)));
+ }
+
+ /**
+ * Test proper free of meter ids.
+ */
+ @Test
+ public void testFreeId() {
+ // Init the store
+ initMeterStore();
+ // Allocate a meter id and verify is equal to mid1
+ assertThat(mid1, is(meterStore.allocateMeterId(did1)));
+ // Free the above id
+ meterStore.freeMeterId(did1, mid1);
+ // Allocate a meter id and verify is equal to mid1
+ assertThat(mid1, is(meterStore.allocateMeterId(did1)));
+ // Free an id not allocated
+ meterStore.freeMeterId(did1, mid10);
+ // Allocate a meter id and verify is equal to mid2
+ assertThat(mid2, is(meterStore.allocateMeterId(did1)));
+ }
+
+ /**
+ * Test proper reuse of meter ids.
+ */
+ @Test
+ public void testReuseId() {
+ // Init the store
+ initMeterStore();
+ // Reserve id 1
+ MeterId meterIdOne = meterStore.allocateMeterId(did2);
+ // Free the above id
+ meterStore.freeMeterId(did2, meterIdOne);
+ // Start an async reservation
+ CompletableFuture<MeterId> future = CompletableFuture.supplyAsync(
+ () -> meterStore.allocateMeterId(did2)
+ );
+ // Start another reservation
+ MeterId meterIdTwo = meterStore.allocateMeterId(did2);
+ try {
+ meterIdOne = future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ // Ids should be different, otherwise we had clash in the store
+ assertNotEquals("Ids should be different", meterIdOne, meterIdTwo);
+
+ // Free the above id
+ meterStore.freeMeterId(did1, meterIdOne);
+ // Free the above id
+ meterStore.freeMeterId(did1, meterIdTwo);
+ // Reserve id 1
+ meterIdOne = meterStore.allocateMeterId(did2);
+ // Reserve id 2
+ meterStore.allocateMeterId(did2);
+ // Reserve id 3
+ MeterId meterIdThree = meterStore.allocateMeterId(did2);
+ // Reserve id 4
+ MeterId meterIdFour = meterStore.allocateMeterId(did2);
+ // Free the above id
+ meterStore.freeMeterId(did1, meterIdOne);
+ // Free the above id
+ meterStore.freeMeterId(did1, meterIdThree);
+ // Free the above id
+ meterStore.freeMeterId(did1, meterIdFour);
+ // Start an async reservation
+ future = CompletableFuture.supplyAsync(
+ () -> meterStore.allocateMeterId(did2)
+ );
+ // Start another reservation
+ MeterId meterAnotherId = meterStore.allocateMeterId(did2);
+ try {
+ meterAnotherId = future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ // Ids should be different, otherwise we had clash in the store
+ assertNotEquals("Ids should be different", meterAnotherId, meterIdOne);
+ }
+
+ /**
+ * Test query meters mechanism.
+ */
+ @Test
+ public void testQueryMeters() {
+ // Init the store
+ initMeterStore();
+ // Let's test queryMeters
+ assertThat(mid1, is(meterStore.allocateMeterId(did3)));
+ // Let's test queryMeters error
+ assertNull(meterStore.allocateMeterId(did4));
+ }
+
+ /**
+ * Test max meter error.
+ */
+ @Test
+ public void testMaxMeterError() {
+ // Init the store
+ initMeterStore();
+ // Reserve id 1
+ assertThat(mid1, is(meterStore.allocateMeterId(did1)));
+ // Reserve id 2
+ assertThat(mid2, is(meterStore.allocateMeterId(did1)));
+ // Max meter error
+ assertNull(meterStore.allocateMeterId(did1));
+ }
+
+ /**
+ * Test store meter.
+ */
+ @Test
+ public void testStoreMeter() {
+ // Init the store
+ initMeterStore();
+ // Simulate the allocation of an id
+ MeterId idOne = meterStore.allocateMeterId(did1);
+ // Verify the allocation
+ assertThat(mid1, is(idOne));
+ // Let's create a meter
+ Meter meterOne = DefaultMeter.builder()
+ .forDevice(did1)
+ .fromApp(APP_ID)
+ .withId(mid1)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(Collections.singletonList(b1))
+ .build();
+ // Set the state
+ ((DefaultMeter) meterOne).setState(MeterState.PENDING_ADD);
+ // Store the meter
+ meterStore.storeMeter(meterOne);
+ // Let's create meter key
+ MeterKey meterKey = MeterKey.key(did1, mid1);
+ // Verify the store
+ assertThat(1, is(meterStore.getAllMeters().size()));
+ assertThat(1, is(meterStore.getAllMeters(did1).size()));
+ assertThat(m1, is(meterStore.getMeter(meterKey)));
+ }
+
+ /**
+ * Test delete meter.
+ */
+ @Test
+ public void testDeleteMeter() {
+ // Init the store
+ initMeterStore();
+ // Simulate the allocation of an id
+ MeterId idOne = meterStore.allocateMeterId(did1);
+ // Verify the allocation
+ assertThat(mid1, is(idOne));
+ // Let's create a meter
+ Meter meterOne = DefaultMeter.builder()
+ .forDevice(did1)
+ .fromApp(APP_ID)
+ .withId(mid1)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(Collections.singletonList(b1))
+ .build();
+ // Set the state
+ ((DefaultMeter) meterOne).setState(MeterState.PENDING_ADD);
+ // Store the meter
+ meterStore.storeMeter(meterOne);
+ // Set the state
+ ((DefaultMeter) meterOne).setState(MeterState.PENDING_REMOVE);
+ // Let's create meter key
+ MeterKey meterKey = MeterKey.key(did1, mid1);
+ // Delete meter
+ meterStore.deleteMeter(meterOne);
+ // Start an async delete, simulating the operation of the provider
+ CompletableFuture<Void> future = CompletableFuture.runAsync(
+ () -> meterStore.deleteMeterNow(meterOne)
+ );
+ // Let's wait
+ try {
+ future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
+ }
+ // Verify delete
+ assertThat(0, is(meterStore.getAllMeters().size()));
+ assertThat(0, is(meterStore.getAllMeters(did1).size()));
+ assertNull(meterStore.getMeter(meterKey));
+ assertThat(mid1, is(meterStore.allocateMeterId(did1)));
+ }
+
+ /**
+ * Test no delete meter.
+ */
+ @Test
+ public void testNoDeleteMeter() {
+ // Init the store
+ initMeterStore();
+ // Simulate the allocation of an id
+ MeterId idOne = meterStore.allocateMeterId(did1);
+ // Create the key
+ MeterKey keyOne = MeterKey.key(did1, idOne);
+ // Let's create a meter
+ Meter meterOne = DefaultMeter.builder()
+ .forDevice(did1)
+ .fromApp(APP_ID)
+ .withId(mid1)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(Collections.singletonList(b1))
+ .build();
+ // Set the state
+ ((DefaultMeter) meterOne).setState(MeterState.PENDING_REMOVE);
+ // Delete meter
+ meterStore.deleteMeter(meterOne);
+ // Verify No delete
+ assertThat(0, is(meterStore.getAllMeters().size()));
+ assertThat(0, is(meterStore.getAllMeters(did1).size()));
+ assertNull(meterStore.getMeter(keyOne));
+ }
+
+ // Test cluster service
+ private final class TestClusterService extends ClusterServiceAdapter {
+
+ private ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST);
+
+ @Override
+ public ControllerNode getLocalNode() {
+ return local;
+ }
+
+ @Override
+ public Set<ControllerNode> getNodes() {
+ return Sets.newHashSet();
+ }
+
+ }
+
+ // Test mastership service
+ private final class TestMastershipService extends MastershipServiceAdapter {
+ @Override
+ public NodeId getMasterFor(DeviceId deviceId) {
+ return NID_LOCAL;
+ }
+ }
+
+ // Test class for driver service.
+ private class TestDriverService extends DriverServiceAdapter {
+ @Override
+ public DriverHandler createHandler(DeviceId deviceId, String... credentials) {
+ return deviceId.equals(did3) ? new TestDriverHandler() : null;
+ }
+ }
+
+ // Test class for driver handler.
+ private class TestDriverHandler implements DriverHandler {
+
+ @Override
+ public Driver driver() {
+ return null;
+ }
+
+ @Override
+ public DriverData data() {
+ return null;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T extends Behaviour> T behaviour(Class<T> behaviourClass) {
+ return (T) new TestMeterQuery();
+ }
+
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ return null;
+ }
+
+ @Override
+ public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) {
+ return true;
+ }
+ }
+
+ // Test meter query
+ private class TestMeterQuery implements MeterQuery {
+
+ @Override
+ public DriverData data() {
+ return null;
+ }
+
+ @Override
+ public void setData(DriverData data) {
+
+ }
+ @Override
+ public DriverHandler handler() {
+ return null;
+ }
+
+ @Override
+ public void setHandler(DriverHandler handler) {
+
+ }
+
+ @Override
+ public long getMaxMeters() {
+ return 100;
+ }
+ }
+
+}
diff --git a/core/store/primitives/BUILD b/core/store/primitives/BUILD
index 45f0b4e..aad4b68 100644
--- a/core/store/primitives/BUILD
+++ b/core/store/primitives/BUILD
@@ -1,7 +1,6 @@
COMPILE_DEPS = CORE_DEPS + KRYO + ATOMIX + [
"//core/common:onos-core-common",
"//core/store/serializers:onos-core-serializers",
- "//incubator/api:onos-incubator-api",
]
TEST_DEPS = TEST + [
diff --git a/core/store/serializers/BUILD b/core/store/serializers/BUILD
index 6b51c34..c2a708a 100644
--- a/core/store/serializers/BUILD
+++ b/core/store/serializers/BUILD
@@ -1,6 +1,4 @@
-COMPILE_DEPS = CORE_DEPS + KRYO + [
- "//incubator/api:onos-incubator-api",
-]
+COMPILE_DEPS = CORE_DEPS + KRYO
TEST_DEPS = TEST
diff --git a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
index 0fd964e..b612efa 100644
--- a/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
+++ b/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
@@ -53,7 +53,6 @@
import org.onosproject.core.GroupId;
import org.onosproject.core.Version;
import org.onosproject.event.Change;
-import org.onosproject.incubator.net.domain.IntentDomainId;
import org.onosproject.mastership.MastershipTerm;
import org.onosproject.net.Annotations;
import org.onosproject.net.ChannelSpacing;
@@ -586,7 +585,6 @@
DefaultAnnotations.class,
PortStatistics.class,
DefaultPortStatistics.class,
- IntentDomainId.class,
TableStatisticsEntry.class,
DefaultTableStatisticsEntry.class,
EncapsulationConstraint.class,