Committed by
Gerrit Code Review
Define Lambda interface representing wavelength and implementations
Two Lambda implementations are defined. - IndexedLambda - OchSignal Change-Id: I36763390f61abd9f861e76edab63f558ae97e8a2
Showing
6 changed files
with
298 additions
and
2 deletions
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 Lambda simply designated by an index number of wavelength. | ||
22 | + */ | ||
23 | +public class IndexedLambda implements Lambda { | ||
24 | + | ||
25 | + private final long lambda; | ||
26 | + | ||
27 | + /** | ||
28 | + * Creates an instance representing the wavelength specified by the given index number. | ||
29 | + * | ||
30 | + * @param lambda index number of wavelength | ||
31 | + */ | ||
32 | + IndexedLambda(long lambda) { | ||
33 | + this.lambda = lambda; | ||
34 | + } | ||
35 | + | ||
36 | + @Override | ||
37 | + public int hashCode() { | ||
38 | + return (int) (lambda ^ (lambda >>> 32)); | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public boolean equals(Object obj) { | ||
43 | + if (this == obj) { | ||
44 | + return true; | ||
45 | + } | ||
46 | + if (!(obj instanceof IndexedLambda)) { | ||
47 | + return false; | ||
48 | + } | ||
49 | + | ||
50 | + final IndexedLambda that = (IndexedLambda) obj; | ||
51 | + return this.lambda == that.lambda; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public String toString() { | ||
56 | + return MoreObjects.toStringHelper(this) | ||
57 | + .add("lambda", lambda) | ||
58 | + .toString(); | ||
59 | + } | ||
60 | +} |
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 | +/** | ||
19 | + * Abstraction of wavelength. Currently, this is just a marker interface | ||
20 | + */ | ||
21 | +public interface Lambda { | ||
22 | + /** | ||
23 | + * Create an Lambda instance with the specified wavelength index number. | ||
24 | + * | ||
25 | + * @param lambda index number | ||
26 | + * @return an instance | ||
27 | + */ | ||
28 | + static Lambda indexedLambda(long lambda) { | ||
29 | + return new IndexedLambda(lambda); | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * Creates a Lambda instance with the specified arguments. | ||
34 | + * | ||
35 | + * @param gridType grid type | ||
36 | + * @param channelSpacing channel spacing | ||
37 | + * @param spacingMultiplier channel spacing multiplier | ||
38 | + * @param slotGranularity slot width granularity | ||
39 | + */ | ||
40 | + static Lambda ochSignal(GridType gridType, ChannelSpacing channelSpacing, | ||
41 | + int spacingMultiplier, int slotGranularity) { | ||
42 | + return new OchSignal(gridType, channelSpacing, spacingMultiplier, slotGranularity); | ||
43 | + } | ||
44 | +} |
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 | +import org.onlab.util.Frequency; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | + | ||
23 | +import static com.google.common.base.Preconditions.checkArgument; | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | + | ||
26 | +/** | ||
27 | + * Implementation of Lambda representing OCh (Optical Channel) Signal. | ||
28 | + * | ||
29 | + * <p> | ||
30 | + * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)". | ||
31 | + * </p> | ||
32 | + */ | ||
33 | +// TODO: consider which is better, OchSignal or OpticalChannelSignal | ||
34 | +public class OchSignal implements Lambda { | ||
35 | + | ||
36 | + private static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1); | ||
37 | + private static final Frequency FLEX_GRID_SLOT = Frequency.ofGHz(12.5); | ||
38 | + | ||
39 | + private final GridType gridType; | ||
40 | + private final ChannelSpacing channelSpacing; | ||
41 | + // Frequency = 193.1 THz + spacingMultiplier * channelSpacing | ||
42 | + private final int spacingMultiplier; | ||
43 | + // Slot width = slotGranularity * 12.5 GHz | ||
44 | + private final int slotGranularity; | ||
45 | + | ||
46 | + /** | ||
47 | + * Creates an instance with the specified arguments. | ||
48 | + * | ||
49 | + * @param gridType grid type | ||
50 | + * @param channelSpacing channel spacing | ||
51 | + * @param spacingMultiplier channel spacing multiplier | ||
52 | + * @param slotGranularity slot width granularity | ||
53 | + */ | ||
54 | + OchSignal(GridType gridType, ChannelSpacing channelSpacing, | ||
55 | + int spacingMultiplier, int slotGranularity) { | ||
56 | + this.gridType = checkNotNull(gridType); | ||
57 | + this.channelSpacing = checkNotNull(channelSpacing); | ||
58 | + // TODO: check the precondition for spacingMultiplier. Is negative value permitted? | ||
59 | + this.spacingMultiplier = spacingMultiplier; | ||
60 | + | ||
61 | + checkArgument(slotGranularity > 0, "slotGranularity must be more than 0, but %s", slotGranularity); | ||
62 | + this.slotGranularity = slotGranularity; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Returns grid type. | ||
67 | + * | ||
68 | + * @return grid type | ||
69 | + */ | ||
70 | + public GridType gridType() { | ||
71 | + return gridType; | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * Returns channel spacing. | ||
76 | + * | ||
77 | + * @return channel spacing | ||
78 | + */ | ||
79 | + public ChannelSpacing channelSpacing() { | ||
80 | + return channelSpacing; | ||
81 | + } | ||
82 | + | ||
83 | + /** | ||
84 | + * Returns spacing multiplier. | ||
85 | + * | ||
86 | + * @return spacing multiplier | ||
87 | + */ | ||
88 | + public int spacingMultiplier() { | ||
89 | + return spacingMultiplier; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Returns slow width granularity. | ||
94 | + * | ||
95 | + * @return slow width granularity | ||
96 | + */ | ||
97 | + public int slotGranularity() { | ||
98 | + return slotGranularity; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Returns central frequency in MHz. | ||
103 | + * | ||
104 | + * @return frequency in MHz | ||
105 | + */ | ||
106 | + public Frequency centralFrequency() { | ||
107 | + return CENTER_FREQUENCY.add(channelSpacing().frequency().multiply(spacingMultiplier)); | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Returns slot width. | ||
112 | + * | ||
113 | + * @return slot width | ||
114 | + */ | ||
115 | + public Frequency slotWidth() { | ||
116 | + return FLEX_GRID_SLOT.multiply(slotGranularity); | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public int hashCode() { | ||
121 | + return Objects.hash(gridType, channelSpacing, spacingMultiplier, slotGranularity); | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public boolean equals(Object obj) { | ||
126 | + if (this == obj) { | ||
127 | + return true; | ||
128 | + } | ||
129 | + if (!(obj instanceof OchSignal)) { | ||
130 | + return false; | ||
131 | + } | ||
132 | + final OchSignal other = (OchSignal) obj; | ||
133 | + return Objects.equals(this.gridType, other.gridType) | ||
134 | + && Objects.equals(this.channelSpacing, other.channelSpacing) | ||
135 | + && Objects.equals(this.spacingMultiplier, other.spacingMultiplier) | ||
136 | + && Objects.equals(this.slotGranularity, other.slotGranularity); | ||
137 | + } | ||
138 | + | ||
139 | + @Override | ||
140 | + public String toString() { | ||
141 | + return MoreObjects.toStringHelper(this) | ||
142 | + .add("gridType", gridType) | ||
143 | + .add("channelSpacing", channelSpacing) | ||
144 | + .add("spacingMultiplier", spacingMultiplier) | ||
145 | + .add("slotGranularity", slotGranularity) | ||
146 | + .toString(); | ||
147 | + } | ||
148 | +} |
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.testing.EqualsTester; | ||
19 | +import org.junit.Test; | ||
20 | + | ||
21 | +public class IndexedLambdaTest { | ||
22 | + @Test | ||
23 | + public void testEquality() { | ||
24 | + new EqualsTester() | ||
25 | + .addEqualityGroup(Lambda.indexedLambda(10), Lambda.indexedLambda(10)) | ||
26 | + .addEqualityGroup(Lambda.indexedLambda(11), Lambda.indexedLambda(11), Lambda.indexedLambda(11)) | ||
27 | + .testEquals(); | ||
28 | + } | ||
29 | +} |
... | @@ -18,7 +18,6 @@ package org.onosproject.store.serializers; | ... | @@ -18,7 +18,6 @@ package org.onosproject.store.serializers; |
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | import com.google.common.collect.ImmutableMap; | 19 | import com.google.common.collect.ImmutableMap; |
20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
21 | - | ||
22 | import org.onlab.packet.ChassisId; | 21 | import org.onlab.packet.ChassisId; |
23 | import org.onlab.packet.Ip4Address; | 22 | import org.onlab.packet.Ip4Address; |
24 | import org.onlab.packet.Ip4Prefix; | 23 | import org.onlab.packet.Ip4Prefix; |
... | @@ -57,14 +56,16 @@ import org.onosproject.net.Element; | ... | @@ -57,14 +56,16 @@ import org.onosproject.net.Element; |
57 | import org.onosproject.net.GridType; | 56 | import org.onosproject.net.GridType; |
58 | import org.onosproject.net.HostId; | 57 | import org.onosproject.net.HostId; |
59 | import org.onosproject.net.HostLocation; | 58 | import org.onosproject.net.HostLocation; |
59 | +import org.onosproject.net.IndexedLambda; | ||
60 | import org.onosproject.net.Link; | 60 | import org.onosproject.net.Link; |
61 | import org.onosproject.net.LinkKey; | 61 | import org.onosproject.net.LinkKey; |
62 | import org.onosproject.net.OchPort; | 62 | import org.onosproject.net.OchPort; |
63 | +import org.onosproject.net.OchSignal; | ||
63 | import org.onosproject.net.OduCltPort; | 64 | import org.onosproject.net.OduCltPort; |
65 | +import org.onosproject.net.OduSignalType; | ||
64 | import org.onosproject.net.OmsPort; | 66 | import org.onosproject.net.OmsPort; |
65 | import org.onosproject.net.Port; | 67 | import org.onosproject.net.Port; |
66 | import org.onosproject.net.PortNumber; | 68 | import org.onosproject.net.PortNumber; |
67 | -import org.onosproject.net.OduSignalType; | ||
68 | import org.onosproject.net.device.DefaultDeviceDescription; | 69 | import org.onosproject.net.device.DefaultDeviceDescription; |
69 | import org.onosproject.net.device.DefaultPortDescription; | 70 | import org.onosproject.net.device.DefaultPortDescription; |
70 | import org.onosproject.net.flow.CompletedBatchOperation; | 71 | import org.onosproject.net.flow.CompletedBatchOperation; |
... | @@ -384,6 +385,8 @@ public final class KryoNamespaces { | ... | @@ -384,6 +385,8 @@ public final class KryoNamespaces { |
384 | .register(ChannelSpacing.class) | 385 | .register(ChannelSpacing.class) |
385 | .register(OduCltPort.class) | 386 | .register(OduCltPort.class) |
386 | .register(OduCltPort.SignalType.class) | 387 | .register(OduCltPort.SignalType.class) |
388 | + .register(IndexedLambda.class) | ||
389 | + .register(OchSignal.class) | ||
387 | .register( | 390 | .register( |
388 | MplsIntent.class, | 391 | MplsIntent.class, |
389 | MplsPathIntent.class, | 392 | MplsPathIntent.class, | ... | ... |
... | @@ -324,6 +324,18 @@ public class KryoSerializerTest { | ... | @@ -324,6 +324,18 @@ public class KryoSerializerTest { |
324 | } | 324 | } |
325 | 325 | ||
326 | @Test | 326 | @Test |
327 | + public void testIndexedLambda() { | ||
328 | + testSerializedEquals(org.onosproject.net.Lambda.indexedLambda(10L)); | ||
329 | + } | ||
330 | + | ||
331 | + @Test | ||
332 | + public void testOchSignal() { | ||
333 | + testSerializedEquals(org.onosproject.net.Lambda.ochSignal( | ||
334 | + GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1 | ||
335 | + )); | ||
336 | + } | ||
337 | + | ||
338 | + @Test | ||
327 | public void testDefaultLinkResourceRequest() { | 339 | public void testDefaultLinkResourceRequest() { |
328 | testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of()) | 340 | testSerializable(DefaultLinkResourceRequest.builder(IntentId.valueOf(2501), ImmutableList.of()) |
329 | .addLambdaRequest() | 341 | .addLambdaRequest() | ... | ... |
-
Please register or login to post a comment