Rimon Ashkenazy
Committed by Gerrit Code Review

[Emu] Register ODU TributarySlots on OCH ports

Change-Id: Iff6010259485f2402f1b645de8f83af5627bee3c
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net;
17 +
18 +import com.google.common.base.MoreObjects;
19 +
20 +/**
21 + * Implementation of ODU Tributary Slot simply designated by an index number of slot.
22 + */
23 +public class TributarySlot {
24 +
25 + private final long index;
26 +
27 + /**
28 + * Creates an instance representing the TributarySlot specified by the given index number.
29 + *
30 + * @param index index number of wavelength
31 + */
32 + public TributarySlot(long index) {
33 + this.index = index;
34 + }
35 +
36 + public static TributarySlot of(long index) {
37 + return new TributarySlot(index);
38 + }
39 +
40 + /**
41 + * Returns the index number of TributarySlot.
42 + *
43 + * @return the index number of TributarySlot
44 + */
45 + public long index() {
46 + return index;
47 + }
48 +
49 + @Override
50 + public int hashCode() {
51 + return Long.hashCode(index);
52 + }
53 +
54 + @Override
55 + public boolean equals(Object obj) {
56 + if (this == obj) {
57 + return true;
58 + }
59 + if (!(obj instanceof TributarySlot)) {
60 + return false;
61 + }
62 +
63 + final TributarySlot that = (TributarySlot) obj;
64 + return this.index == that.index;
65 + }
66 +
67 + @Override
68 + public String toString() {
69 + return MoreObjects.toStringHelper(this)
70 + .add("index", index)
71 + .toString();
72 + }
73 +}
...@@ -17,12 +17,20 @@ package org.onosproject.net.newresource.impl; ...@@ -17,12 +17,20 @@ package org.onosproject.net.newresource.impl;
17 17
18 import org.onosproject.net.Device; 18 import org.onosproject.net.Device;
19 import org.onosproject.net.Port; 19 import org.onosproject.net.Port;
20 +import org.onosproject.net.OchPort;
21 +import org.onosproject.net.TributarySlot;
22 +import org.onosproject.net.OduSignalType;
20 import org.onosproject.net.device.DeviceEvent; 23 import org.onosproject.net.device.DeviceEvent;
21 import org.onosproject.net.device.DeviceListener; 24 import org.onosproject.net.device.DeviceListener;
22 import org.onosproject.net.newresource.ResourceAdminService; 25 import org.onosproject.net.newresource.ResourceAdminService;
23 import org.onosproject.net.newresource.ResourcePath; 26 import org.onosproject.net.newresource.ResourcePath;
27 +import org.slf4j.Logger;
28 +import org.slf4j.LoggerFactory;
24 29
30 +import java.util.List;
25 import java.util.concurrent.ExecutorService; 31 import java.util.concurrent.ExecutorService;
32 +import java.util.stream.Collectors;
33 +import java.util.stream.IntStream;
26 34
27 import static com.google.common.base.Preconditions.checkNotNull; 35 import static com.google.common.base.Preconditions.checkNotNull;
28 36
...@@ -31,6 +39,13 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -31,6 +39,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
31 */ 39 */
32 final class ResourceDeviceListener implements DeviceListener { 40 final class ResourceDeviceListener implements DeviceListener {
33 41
42 + private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class);
43 +
44 + private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8;
45 + private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80;
46 + private static final List<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots();
47 + private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots();
48 +
34 private final ResourceAdminService adminService; 49 private final ResourceAdminService adminService;
35 private final ExecutorService executor; 50 private final ExecutorService executor;
36 51
...@@ -76,11 +91,50 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -76,11 +91,50 @@ final class ResourceDeviceListener implements DeviceListener {
76 91
77 private void registerPortResource(Device device, Port port) { 92 private void registerPortResource(Device device, Port port) {
78 ResourcePath parent = ResourcePath.discrete(device.id()); 93 ResourcePath parent = ResourcePath.discrete(device.id());
79 - executor.submit(() -> adminService.registerResources(parent, port.number())); 94 + executor.submit(() -> registerPortResource(device, port, parent));
95 + }
96 +
97 + private void registerPortResource(Device device, Port port, ResourcePath parent) {
98 + adminService.registerResources(parent, port.number());
99 + ResourcePath portPath = ResourcePath.discrete(device.id(), port.number());
100 +
101 + switch (port.type()) {
102 + case OCH:
103 + // register ODU TributarySlots against the OCH port
104 + registerTributarySlotsResources(((OchPort) port).signalType(), portPath);
105 + break;
106 + default:
107 + break;
108 + }
109 + }
110 +
111 + private void registerTributarySlotsResources(OduSignalType oduSignalType, ResourcePath portPath) {
112 + switch (oduSignalType) {
113 + case ODU2:
114 + adminService.registerResources(portPath, ENTIRE_ODU2_TRIBUTARY_SLOTS);
115 + break;
116 + case ODU4:
117 + adminService.registerResources(portPath, ENTIRE_ODU4_TRIBUTARY_SLOTS);
118 + break;
119 + default:
120 + break;
121 + }
80 } 122 }
81 123
82 private void unregisterPortResource(Device device, Port port) { 124 private void unregisterPortResource(Device device, Port port) {
83 ResourcePath parent = ResourcePath.discrete(device.id()); 125 ResourcePath parent = ResourcePath.discrete(device.id());
84 executor.submit(() -> adminService.unregisterResources(parent, port.number())); 126 executor.submit(() -> adminService.unregisterResources(parent, port.number()));
85 } 127 }
128 +
129 + private static List<TributarySlot> getEntireOdu2TributarySlots() {
130 + return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS)
131 + .mapToObj(x -> TributarySlot.of(x))
132 + .collect(Collectors.toList());
133 + }
134 + private static List<TributarySlot> getEntireOdu4TributarySlots() {
135 + return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS)
136 + .mapToObj(x -> TributarySlot.of(x))
137 + .collect(Collectors.toList());
138 + }
139 +
86 } 140 }
......
...@@ -75,6 +75,7 @@ import org.onosproject.net.OduSignalType; ...@@ -75,6 +75,7 @@ import org.onosproject.net.OduSignalType;
75 import org.onosproject.net.OmsPort; 75 import org.onosproject.net.OmsPort;
76 import org.onosproject.net.Port; 76 import org.onosproject.net.Port;
77 import org.onosproject.net.PortNumber; 77 import org.onosproject.net.PortNumber;
78 +import org.onosproject.net.TributarySlot;
78 import org.onosproject.net.device.DefaultDeviceDescription; 79 import org.onosproject.net.device.DefaultDeviceDescription;
79 import org.onosproject.net.device.DefaultPortDescription; 80 import org.onosproject.net.device.DefaultPortDescription;
80 import org.onosproject.net.device.DefaultPortStatistics; 81 import org.onosproject.net.device.DefaultPortStatistics;
...@@ -476,6 +477,7 @@ public final class KryoNamespaces { ...@@ -476,6 +477,7 @@ public final class KryoNamespaces {
476 .register(OduCltPortDescription.class) 477 .register(OduCltPortDescription.class)
477 .register(OchPortDescription.class) 478 .register(OchPortDescription.class)
478 .register(OmsPortDescription.class) 479 .register(OmsPortDescription.class)
480 + .register(TributarySlot.class)
479 .register( 481 .register(
480 MplsIntent.class, 482 MplsIntent.class,
481 MplsPathIntent.class, 483 MplsPathIntent.class,
......