[ONOS-4513] Move utilities not specific to optical out of optical package.

Change-Id: Ib4d33008c61f17b8ff220142a0d15db31e5fcfb9
diff --git a/core/api/src/main/java/org/onosproject/net/utils/ForwardingDevice.java b/core/api/src/main/java/org/onosproject/net/utils/ForwardingDevice.java
new file mode 100644
index 0000000..e910ce5
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/utils/ForwardingDevice.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.utils;
+
+import org.onlab.packet.ChassisId;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.driver.Behaviour;
+import org.onosproject.net.provider.ProviderId;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * A Device which forwards all its method calls to another Device.
+ */
+@Beta
+public interface ForwardingDevice extends Device {
+
+    Device delegate();
+
+    @Override
+    default Annotations annotations() {
+        return delegate().annotations();
+    }
+
+    @Override
+    default ProviderId providerId() {
+        return delegate().providerId();
+    }
+
+    @Override
+    default <B extends Behaviour> B as(Class<B> projectionClass) {
+        return delegate().as(projectionClass);
+    }
+
+    @Override
+    default DeviceId id() {
+        return delegate().id();
+    }
+
+    @Override
+    default Type type() {
+        return delegate().type();
+    }
+
+    @Override
+    default <B extends Behaviour> boolean is(Class<B> projectionClass) {
+        return delegate().is(projectionClass);
+    }
+
+    @Override
+    default String manufacturer() {
+        return delegate().manufacturer();
+    }
+
+    @Override
+    default String hwVersion() {
+        return delegate().hwVersion();
+    }
+
+    @Override
+    default String swVersion() {
+        return delegate().swVersion();
+    }
+
+    @Override
+    default String serialNumber() {
+        return delegate().serialNumber();
+    }
+
+    @Override
+    default ChassisId chassisId() {
+        return delegate().chassisId();
+    }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java b/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java
new file mode 100644
index 0000000..91885ba
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/utils/ForwardingDeviceService.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.utils;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.List;
+
+import org.onosproject.net.Device;
+import org.onosproject.net.Device.Type;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.MastershipRole;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.device.PortStatistics;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * A DeviceService which forwards all its method calls to another DeviceService.
+ */
+@Beta
+public abstract class ForwardingDeviceService implements DeviceService {
+
+    private final DeviceService delegate;
+
+    protected ForwardingDeviceService(DeviceService delegate) {
+        this.delegate = checkNotNull(delegate);
+    }
+
+    protected final DeviceService delegate() {
+        return delegate;
+    }
+
+    @Override
+    public void addListener(DeviceListener listener) {
+        delegate.addListener(listener);
+    }
+
+    @Override
+    public void removeListener(DeviceListener listener) {
+        delegate.removeListener(listener);
+    }
+
+    @Override
+    public int getDeviceCount() {
+        return delegate.getDeviceCount();
+    }
+
+    @Override
+    public Iterable<Device> getDevices() {
+        return delegate.getDevices();
+    }
+
+    @Override
+    public Iterable<Device> getDevices(Type type) {
+        return delegate.getDevices(type);
+    }
+
+    @Override
+    public Iterable<Device> getAvailableDevices() {
+        return delegate.getAvailableDevices();
+    }
+
+    @Override
+    public Iterable<Device> getAvailableDevices(Type type) {
+        return delegate.getAvailableDevices(type);
+    }
+
+    @Override
+    public Device getDevice(DeviceId deviceId) {
+        return delegate.getDevice(deviceId);
+    }
+
+    @Override
+    public MastershipRole getRole(DeviceId deviceId) {
+        return delegate.getRole(deviceId);
+    }
+
+    @Override
+    public List<Port> getPorts(DeviceId deviceId) {
+        return delegate.getPorts(deviceId);
+    }
+
+    @Override
+    public List<PortStatistics> getPortStatistics(DeviceId deviceId) {
+        return delegate.getPortStatistics(deviceId);
+    }
+
+    @Override
+    public List<PortStatistics> getPortDeltaStatistics(DeviceId deviceId) {
+        return delegate.getPortDeltaStatistics(deviceId);
+    }
+
+    @Override
+    public Port getPort(DeviceId deviceId, PortNumber portNumber) {
+        return delegate.getPort(deviceId, portNumber);
+    }
+
+    @Override
+    public boolean isAvailable(DeviceId deviceId) {
+        return delegate.isAvailable(deviceId);
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/utils/ForwardingPort.java b/core/api/src/main/java/org/onosproject/net/utils/ForwardingPort.java
new file mode 100644
index 0000000..7485b1e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/utils/ForwardingPort.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.utils;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.Element;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
+
+/**
+ * A Port which forwards all its method calls to another Port.
+ */
+@Beta
+public abstract class ForwardingPort implements Port {
+
+    private final Port delegate;
+
+    protected ForwardingPort(Port delegate) {
+        this.delegate = checkNotNull(delegate);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(element().id(),
+                            number(),
+                            isEnabled(),
+                            type(),
+                            portSpeed(),
+                            annotations());
+    }
+
+    /**
+     * Returns {@link EqualsBuilder} comparing all Port attributes
+     * including annotations.
+     * <p>
+     * To add extra fields to equality,
+     * call {@code super.toEqualsBuilder(..)} and append fields.
+     * To remove field from comparison, override this method
+     * or manually implement equals().
+     */
+    protected EqualsBuilder toEqualsBuilder(Port that) {
+        if (that == null) {
+            return new EqualsBuilder().appendSuper(false);
+        }
+        return new EqualsBuilder()
+                .append(this.element().id(), that.element().id())
+                .append(this.number(), that.number())
+                .append(this.isEnabled(), that.isEnabled())
+                .append(this.type(), that.type())
+                .append(this.portSpeed(), that.portSpeed())
+                .append(this.annotations(), that.annotations());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj != null && getClass() == obj.getClass()) {
+            final ForwardingPort that = (ForwardingPort) obj;
+            return toEqualsBuilder(that)
+                    .isEquals();
+        }
+        return false;
+    }
+
+    /**
+     * Returns {@link ToStringHelper} with Port attributes excluding annotations.
+     *
+     * @return {@link ToStringHelper}
+     */
+    protected ToStringHelper toStringHelper() {
+        return MoreObjects.toStringHelper(this)
+                .add("element", element().id())
+                .add("number", number())
+                .add("isEnabled", isEnabled())
+                .add("type", type())
+                .add("portSpeed", portSpeed());
+    }
+
+    @Override
+    public String toString() {
+        return toStringHelper()
+                .toString();
+    }
+
+    @Override
+    public Annotations annotations() {
+        return delegate.annotations();
+    }
+
+    @Override
+    public Element element() {
+        return delegate.element();
+    }
+
+    @Override
+    public PortNumber number() {
+        return delegate.number();
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return delegate.isEnabled();
+    }
+
+    @Override
+    public Port.Type type() {
+        return delegate.type();
+    }
+
+    @Override
+    public long portSpeed() {
+        return delegate.portSpeed();
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/utils/package-info.java b/core/api/src/main/java/org/onosproject/net/utils/package-info.java
new file mode 100644
index 0000000..da3860a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/utils/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Utility classes.
+ */
+package org.onosproject.net.utils;