Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.drivermanager; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.util.concurrent.atomic.AtomicBoolean; |
| 5 | |
| 6 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeAlreadyStarted; |
| 7 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeCompleted; |
| 8 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeNotStarted; |
| 9 | import net.floodlightcontroller.core.internal.OFSwitchImplBase; |
| 10 | |
| 11 | import org.projectfloodlight.openflow.protocol.OFBarrierRequest; |
| 12 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 13 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 14 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 15 | import 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 | */ |
| 22 | public 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; |
Jonathan Hart | a213bce | 2014-08-11 15:44:07 -0700 | [diff] [blame] | 47 | factory = getFactory(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 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 | } |