blob: d34a372631ddba53da1a95a4e5cc1781ac8872cc [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.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
20import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted;
21import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted;
22import org.projectfloodlight.openflow.protocol.OFFactory;
23import org.projectfloodlight.openflow.protocol.OFMessage;
24
25import java.util.concurrent.atomic.AtomicBoolean;
26
27public class OFSwitchImplSpringOpenTTP extends AbstractOpenFlowSwitch {
28
29 private OFFactory factory;
30
31 private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false);
32
33 @Override
34 public Boolean supportNxRole() {
35 return false;
36 }
37
38
39 @Override
40 public void startDriverHandshake() {
41 log.debug("Starting driver handshake for sw {}", getStringId());
42 if (startDriverHandshakeCalled) {
43 throw new SwitchDriverSubHandshakeAlreadyStarted();
44 }
45 startDriverHandshakeCalled = true;
46 factory = this.factory();
47
48 driverHandshakeComplete.set(true);
49 log.debug("Driver handshake is complete");
50
51 }
52
53 @Override
54 public boolean isDriverHandshakeComplete() {
55 if (!startDriverHandshakeCalled) {
56 throw new SwitchDriverSubHandshakeNotStarted();
57 }
58 return driverHandshakeComplete.get();
59 }
60
61
62
63 @Override
64 public void processDriverHandshakeMessage(OFMessage m) {
65 if (!startDriverHandshakeCalled) {
66 throw new SwitchDriverSubHandshakeNotStarted();
67 }
68 if (driverHandshakeComplete.get()) {
69 throw new SwitchDriverSubHandshakeCompleted(m);
70 }
71 }
72
73}