alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 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.driver.handshaker; |
| 17 | |
| 18 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
| 19 | import org.projectfloodlight.openflow.protocol.OFFlowAdd; |
| 20 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 21 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 22 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 23 | |
| 24 | import java.util.Collections; |
| 25 | import java.util.List; |
| 26 | import java.util.stream.Collectors; |
| 27 | |
| 28 | /** |
| 29 | * Default driver to fallback on if no other driver is available. |
| 30 | */ |
Madan Jampani | 1b8ea34 | 2015-05-27 17:22:59 -0700 | [diff] [blame] | 31 | public class DefaultSwitchHandshaker extends AbstractOpenFlowSwitch { |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 32 | |
| 33 | private static final int LOWEST_PRIORITY = 0; |
| 34 | |
| 35 | @Override |
| 36 | public Boolean supportNxRole() { |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 37 | return false; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void startDriverHandshake() { |
| 42 | if (factory().getVersion() == OFVersion.OF_10) { |
| 43 | OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd(); |
| 44 | fmBuilder.setPriority(LOWEST_PRIORITY); |
alshabib | a2df7b2a | 2015-05-06 13:57:10 -0700 | [diff] [blame] | 45 | sendHandshakeMessage(fmBuilder.build()); |
alshabib | b452fd7 | 2015-04-22 20:46:20 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void processDriverHandshakeMessage(OFMessage m) {} |
| 51 | |
| 52 | @Override |
| 53 | public boolean isDriverHandshakeComplete() { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public List<OFPortDesc> getPorts() { |
| 59 | if (this.factory().getVersion() == OFVersion.OF_10) { |
| 60 | return Collections.unmodifiableList(features.getPorts()); |
| 61 | } else { |
| 62 | return Collections.unmodifiableList( |
| 63 | ports.stream().flatMap(p -> p.getEntries().stream()) |
| 64 | .collect(Collectors.toList())); |
| 65 | } |
| 66 | } |
| 67 | } |