Yuta HIGUCHI | f42a2cc | 2017-05-02 17:04:31 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-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 | */ |
| 16 | package org.onosproject.driver.optical.handshaker; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import java.util.List; |
| 21 | import java.util.Set; |
| 22 | import org.onosproject.net.Device.Type; |
| 23 | import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; |
| 24 | import org.onosproject.openflow.controller.PortDescPropertyType; |
| 25 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 26 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 27 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 28 | import org.slf4j.Logger; |
| 29 | |
| 30 | import com.google.common.collect.ImmutableList; |
| 31 | import com.google.common.collect.ImmutableSet; |
| 32 | |
| 33 | /** |
| 34 | * Handshaker for Polatis fiber switch. |
| 35 | * |
| 36 | */ |
| 37 | public class PolatisHandshaker extends AbstractOpenFlowSwitch |
| 38 | implements OpenFlowOpticalSwitch { |
| 39 | |
| 40 | private static final Logger log = getLogger(PolatisHandshaker.class); |
| 41 | |
| 42 | @Override |
| 43 | public Boolean supportNxRole() { |
| 44 | // Device is OF1.4 so response doesn't matter. |
| 45 | return Boolean.FALSE; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void startDriverHandshake() { |
| 50 | // nothing Device specific required |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public boolean isDriverHandshakeComplete() { |
| 55 | // nothing Device specific to do |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void processDriverHandshakeMessage(OFMessage m) { |
| 61 | // nothing Device specific to do |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Type deviceType() { |
| 66 | return Type.FIBER_SWITCH; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public List<OFPortDesc> getPortsOf(PortDescPropertyType type) { |
| 71 | return this.getPorts().stream() |
| 72 | .filter(pd -> isPortType(type, pd)) |
| 73 | .collect(ImmutableList.toImmutableList()); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Tests if OFPortDesc {@code pd} is a {@code type}. |
| 78 | * |
| 79 | * @param type to test if {@code pd} is of port type |
| 80 | * @param pd OpenFlow port description to test. |
| 81 | * @return true if {@code pd} is of port description of {@code type} |
| 82 | */ |
| 83 | private static boolean isPortType(PortDescPropertyType type, OFPortDesc pd) { |
| 84 | try { |
| 85 | return pd.getProperties().stream() |
| 86 | .anyMatch(prop -> prop.getType() == type.valueOf()); |
| 87 | } catch (UnsupportedOperationException e) { |
| 88 | log.warn("Unexpected OFPortDesc {} reveived", pd, e); |
| 89 | return false; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public Set<PortDescPropertyType> getPortTypes() { |
| 95 | return ImmutableSet.of(PortDescPropertyType.OPTICAL); |
| 96 | } |
| 97 | } |