blob: c9455a05ffba2fb2ce245b4b41ad6a03afc336b1 [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 */
31public class DefaultSwitchHandShaker extends AbstractOpenFlowSwitch {
32
33 private static final int LOWEST_PRIORITY = 0;
34
35 @Override
36 public Boolean supportNxRole() {
37 if (this.factory().getVersion() == OFVersion.OF_10) {
38 return true;
39 }
40 return false;
41 }
42
43 @Override
44 public void startDriverHandshake() {
45 if (factory().getVersion() == OFVersion.OF_10) {
46 OFFlowAdd.Builder fmBuilder = factory().buildFlowAdd();
47 fmBuilder.setPriority(LOWEST_PRIORITY);
48 sendMsg(fmBuilder.build());
49 }
50 }
51
52 @Override
53 public void processDriverHandshakeMessage(OFMessage m) {}
54
55 @Override
56 public boolean isDriverHandshakeComplete() {
57 return true;
58 }
59
60 @Override
61 public List<OFPortDesc> getPorts() {
62 if (this.factory().getVersion() == OFVersion.OF_10) {
63 return Collections.unmodifiableList(features.getPorts());
64 } else {
65 return Collections.unmodifiableList(
66 ports.stream().flatMap(p -> p.getEntries().stream())
67 .collect(Collectors.toList()));
68 }
69 }
70}