blob: efe43a02237dafee50a1d736d0d1db425175f90e [file] [log] [blame]
Brian O'Connorc67f9fa2014-08-07 18:17:46 -07001package net.onrc.onos.core.drivermanager;
2
3import java.io.IOException;
4import java.util.concurrent.atomic.AtomicBoolean;
5
6import net.floodlightcontroller.core.SwitchDriverSubHandshakeAlreadyStarted;
7import net.floodlightcontroller.core.SwitchDriverSubHandshakeCompleted;
8import net.floodlightcontroller.core.SwitchDriverSubHandshakeNotStarted;
9import net.floodlightcontroller.core.internal.OFSwitchImplBase;
10
11import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
12import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
13import org.projectfloodlight.openflow.protocol.OFErrorMsg;
14import org.projectfloodlight.openflow.protocol.OFFactory;
15import org.projectfloodlight.openflow.protocol.OFMessage;
16
17/**
18 * OFDescriptionStatistics Vendor (Manufacturer Desc.): Nicira, Inc. Make
19 * (Hardware Desc.) : Open vSwitch Model (Datapath Desc.) : None Software :
20 * 2.1.0 (or whatever version + build) Serial : None
21 */
22public class OFSwitchImplOVS13 extends OFSwitchImplBase {
23 private AtomicBoolean driverHandshakeComplete;
24 private OFFactory factory;
25 private long barrierXidToWaitFor = -1;
26
27 public OFSwitchImplOVS13(OFDescStatsReply desc) {
28 super();
29 driverHandshakeComplete = new AtomicBoolean(false);
30 setSwitchDescription(desc);
31 }
32
33 @Override
34 public String toString() {
35 return "OFSwitchImplOVS13 [" + ((channel != null)
36 ? channel.getRemoteAddress() : "?")
37 + " DPID[" + ((stringId != null) ? stringId : "?") + "]]";
38 }
39
40 @Override
41 public void startDriverHandshake() throws IOException {
42 log.debug("Starting driver handshake for sw {}", getStringId());
43 if (startDriverHandshakeCalled) {
44 throw new SwitchDriverSubHandshakeAlreadyStarted();
45 }
46 startDriverHandshakeCalled = true;
47 factory = floodlightProvider.getOFMessageFactory_13();
48 configureSwitch();
49 }
50
51 @Override
52 public boolean isDriverHandshakeComplete() {
53 if (!startDriverHandshakeCalled) {
54 throw new SwitchDriverSubHandshakeNotStarted();
55 }
56 return driverHandshakeComplete.get();
57 }
58
59 @Override
60 public void processDriverHandshakeMessage(OFMessage m) {
61 if (!startDriverHandshakeCalled) {
62 throw new SwitchDriverSubHandshakeNotStarted();
63 }
64 if (driverHandshakeComplete.get()) {
65 throw new SwitchDriverSubHandshakeCompleted(m);
66 }
67
68 switch (m.getType()) {
69 case BARRIER_REPLY:
70 if (m.getXid() == barrierXidToWaitFor) {
71 driverHandshakeComplete.set(true);
72 }
73 break;
74
75 case ERROR:
76 log.error("Switch {} Error {}", getStringId(), (OFErrorMsg) m);
77 break;
78
79 case FEATURES_REPLY:
80 break;
81 case FLOW_REMOVED:
82 break;
83 case GET_ASYNC_REPLY:
84 // OFAsyncGetReply asrep = (OFAsyncGetReply)m;
85 // decodeAsyncGetReply(asrep);
86 break;
87
88 case PACKET_IN:
89 break;
90 case PORT_STATUS:
91 break;
92 case QUEUE_GET_CONFIG_REPLY:
93 break;
94 case ROLE_REPLY:
95 break;
96
97 case STATS_REPLY:
98 // processStatsReply((OFStatsReply) m);
99 break;
100
101 default:
102 log.debug("Received message {} during switch-driver subhandshake "
103 + "from switch {} ... Ignoring message", m, getStringId());
104
105 }
106 }
107
108
109 private void configureSwitch() throws IOException {
110 // setAsyncConfig();
111 // getTableFeatures();
112 /*sendGroupFeaturesRequest();
113 setL2Groups();
114 sendBarrier(false);
115 setL3Groups();
116 setL25Groups();
117 sendGroupDescRequest();*/
118 // populateTableVlan();
119 // populateTableTMac();
120 // populateIpTable();
121 // populateMplsTable();
122 // populateTableMissEntry(TABLE_ACL, false, false, false, -1);
123 sendBarrier(true);
124 }
125
126
127 private void sendBarrier(boolean finalBarrier) throws IOException {
128 int xid = getNextTransactionId();
129 if (finalBarrier) {
130 barrierXidToWaitFor = xid;
131 }
132 OFBarrierRequest br = factory
133 .buildBarrierRequest()
134 .setXid(xid)
135 .build();
136 write(br, null);
137 }
138}