blob: fb7894409046a17099d95d696b2df362e7603597 [file] [log] [blame]
alshabibb452fd72015-04-22 20:46:20 -07001/*
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 */
16package org.onosproject.driver.handshaker;
17
18import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
19import org.projectfloodlight.openflow.protocol.OFFlowAdd;
20import org.projectfloodlight.openflow.protocol.OFMessage;
21import org.projectfloodlight.openflow.protocol.OFPortDesc;
22import org.projectfloodlight.openflow.protocol.OFVersion;
23
24import java.util.Collections;
25import java.util.List;
26import java.util.stream.Collectors;
27
28/**
29 * Default driver to fallback on if no other driver is available.
30 */
Madan Jampani1b8ea342015-05-27 17:22:59 -070031public class DefaultSwitchHandshaker extends AbstractOpenFlowSwitch {
alshabibb452fd72015-04-22 20:46:20 -070032
33 private static final int LOWEST_PRIORITY = 0;
34
35 @Override
36 public Boolean supportNxRole() {
alshabibb452fd72015-04-22 20:46:20 -070037 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);
alshabiba2df7b2a2015-05-06 13:57:10 -070045 sendHandshakeMessage(fmBuilder.build());
alshabibb452fd72015-04-22 20:46:20 -070046 }
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}