blob: 6eeb63181180251dc202befbbcec599b06fb4461 [file] [log] [blame]
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -07001/*
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.OduCltPort;
22import org.onosproject.net.optical.device.OduCltPortHelper;
23import org.onosproject.net.optical.impl.DefaultOduCltPort;
24
25import com.google.common.annotations.Beta;
26
27/**
28 * {@link PortMapper} to handler {@link OduCltPort} translation.
29 */
30@Beta
31public class OduCltPortMapper extends AbstractPortMapper<OduCltPort> {
32
33 @Override
34 public boolean is(Port port) {
35 return port != null &&
36 port.type() == Port.Type.ODUCLT &&
37 super.is(port);
38 }
39
40 @Override
41 public Optional<OduCltPort> as(Port port) {
42 if (port instanceof OduCltPort) {
43 return Optional.of((OduCltPort) port);
44 }
45 return super.as(port);
46 }
47
48 @Override
49 protected Optional<OduCltPort> mapPort(Port port) {
50 if (port instanceof OduCltPort) {
51 return Optional.of((OduCltPort) port);
52 } else if (port instanceof org.onosproject.net.OduCltPort) {
53 // TODO remove after deprecation of old OduCltPort is complete
54
55 // translate to new OduCltPort
56 org.onosproject.net.OduCltPort old = (org.onosproject.net.OduCltPort) port;
57 return Optional.of(new DefaultOduCltPort(old,
58 old.signalType()));
59 }
60
61 return OduCltPortHelper.asOduCltPort(port);
62 }
63
64}