blob: badca9ddda885654869abd6cd7cfd6bcfa70fefd [file] [log] [blame]
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001/*
2 * Copyright 2016-present 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 */
16package org.onosproject.net.optical.device.port;
17
18import java.util.Optional;
19
20import org.onosproject.net.Port;
21import org.onosproject.net.optical.OchPort;
22import org.onosproject.net.optical.device.OchPortHelper;
23import org.onosproject.net.optical.impl.DefaultOchPort;
24
25import com.google.common.annotations.Beta;
26
27/**
28 * {@link PortMapper} to handler {@link OchPort} translation.
29 */
30@Beta
31public class OchPortMapper extends AbstractPortMapper<OchPort> {
32
33 @Override
34 public boolean is(Port port) {
35 return port != null &&
36 port.type() == Port.Type.OCH &&
37 super.is(port);
38 }
39
40 @Override
41 public Optional<OchPort> as(Port port) {
42 if (port instanceof OchPort) {
43 return Optional.of((OchPort) port);
44 }
45 return super.as(port);
46 }
47
48 @Override
49 protected Optional<OchPort> mapPort(Port port) {
50 if (port instanceof OchPort) {
51 return Optional.of((OchPort) port);
52 } else if (port instanceof org.onosproject.net.OchPort) {
53 // TODO remove after deprecation of old OchPort is complete
54
55 // translate to new OchPort
56 org.onosproject.net.OchPort old = (org.onosproject.net.OchPort) port;
57 return Optional.of(new DefaultOchPort(old,
58 old.signalType(),
59 old.isTunable(),
60 old.lambda()));
61 }
62
63 return OchPortHelper.asOchPort(port);
64 }
65}