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.ArrayList; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 5 | import java.util.Collection; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 6 | import java.util.Collections; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 7 | import java.util.HashSet; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 8 | import java.util.List; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 9 | import java.util.Set; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 10 | import java.util.concurrent.ConcurrentHashMap; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 11 | import java.util.concurrent.ConcurrentMap; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 12 | import java.util.concurrent.atomic.AtomicBoolean; |
| 13 | |
| 14 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 15 | import net.floodlightcontroller.core.IOF13Switch; |
| 16 | import net.floodlightcontroller.core.IOFSwitch; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 17 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeAlreadyStarted; |
| 18 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeCompleted; |
| 19 | import net.floodlightcontroller.core.SwitchDriverSubHandshakeNotStarted; |
| 20 | import net.floodlightcontroller.core.internal.OFSwitchImplBase; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 21 | import net.floodlightcontroller.util.MACAddress; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 22 | import net.onrc.onos.core.configmanager.INetworkConfigService; |
| 23 | import net.onrc.onos.core.configmanager.INetworkConfigService.NetworkConfigState; |
| 24 | import net.onrc.onos.core.configmanager.INetworkConfigService.SwitchConfigStatus; |
| 25 | import net.onrc.onos.core.configmanager.NetworkConfig.LinkConfig; |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 26 | import net.onrc.onos.core.configmanager.NetworkConfig.SwitchConfig; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 27 | import net.onrc.onos.core.configmanager.NetworkConfigManager; |
| 28 | import net.onrc.onos.core.configmanager.PktLinkConfig; |
| 29 | import net.onrc.onos.core.configmanager.SegmentRouterConfig; |
| 30 | import net.onrc.onos.core.matchaction.MatchAction; |
| 31 | import net.onrc.onos.core.matchaction.MatchActionOperationEntry; |
Saurav Das | bc594a4 | 2014-09-25 20:13:50 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.matchaction.MatchActionOperations; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.matchaction.MatchActionOperations.Operator; |
| 34 | import net.onrc.onos.core.matchaction.action.Action; |
| 35 | import net.onrc.onos.core.matchaction.action.CopyTtlInAction; |
| 36 | import net.onrc.onos.core.matchaction.action.CopyTtlOutAction; |
| 37 | import net.onrc.onos.core.matchaction.action.DecMplsTtlAction; |
| 38 | import net.onrc.onos.core.matchaction.action.DecNwTtlAction; |
| 39 | import net.onrc.onos.core.matchaction.action.GroupAction; |
| 40 | import net.onrc.onos.core.matchaction.action.ModifyDstMacAction; |
| 41 | import net.onrc.onos.core.matchaction.action.ModifySrcMacAction; |
| 42 | import net.onrc.onos.core.matchaction.action.OutputAction; |
| 43 | import net.onrc.onos.core.matchaction.action.PopMplsAction; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 44 | import net.onrc.onos.core.matchaction.match.Ipv4Match; |
| 45 | import net.onrc.onos.core.matchaction.match.Match; |
| 46 | import net.onrc.onos.core.matchaction.match.MplsMatch; |
| 47 | import net.onrc.onos.core.matchaction.match.PacketMatch; |
| 48 | import net.onrc.onos.core.util.Dpid; |
| 49 | import net.onrc.onos.core.util.IPv4Net; |
| 50 | import net.onrc.onos.core.util.PortNumber; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 51 | |
| 52 | import org.projectfloodlight.openflow.protocol.OFAsyncGetReply; |
| 53 | import org.projectfloodlight.openflow.protocol.OFBarrierRequest; |
| 54 | import org.projectfloodlight.openflow.protocol.OFBucket; |
| 55 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
| 56 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
| 57 | import org.projectfloodlight.openflow.protocol.OFFactory; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 59 | import org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply; |
| 60 | import org.projectfloodlight.openflow.protocol.OFGroupFeaturesStatsReply; |
| 61 | import org.projectfloodlight.openflow.protocol.OFGroupType; |
| 62 | import org.projectfloodlight.openflow.protocol.OFMatchV3; |
| 63 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 64 | import org.projectfloodlight.openflow.protocol.OFOxmList; |
| 65 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 66 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
| 67 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 68 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 69 | import org.projectfloodlight.openflow.protocol.match.Match.Builder; |
| 70 | import org.projectfloodlight.openflow.protocol.match.MatchField; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 71 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEthDst; |
| 72 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEthSrc; |
| 73 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmEthType; |
| 74 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmInPort; |
| 75 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmIpv4DstMasked; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 76 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmMplsLabel; |
| 77 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmVlanVid; |
| 78 | import org.projectfloodlight.openflow.types.EthType; |
| 79 | import org.projectfloodlight.openflow.types.IPv4Address; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 80 | import org.projectfloodlight.openflow.types.IpProtocol; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 81 | import org.projectfloodlight.openflow.types.MacAddress; |
| 82 | import org.projectfloodlight.openflow.types.OFBufferId; |
| 83 | import org.projectfloodlight.openflow.types.OFGroup; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 84 | import org.projectfloodlight.openflow.types.OFPort; |
| 85 | import org.projectfloodlight.openflow.types.OFVlanVidMatch; |
| 86 | import org.projectfloodlight.openflow.types.TableId; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 87 | import org.projectfloodlight.openflow.types.TransportPort; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 88 | import org.projectfloodlight.openflow.types.U32; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 89 | import org.projectfloodlight.openflow.util.HexString; |
| 90 | |
| 91 | /** |
| 92 | * OFDescriptionStatistics Vendor (Manufacturer Desc.): Stanford University, |
| 93 | * Ericsson Research and CPqD Research. Make (Hardware Desc.) : OpenFlow 1.3 |
| 94 | * Reference Userspace Switch Model (Datapath Desc.) : None Software : Serial : |
| 95 | * None |
| 96 | */ |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 97 | public class OFSwitchImplCPqD13 extends OFSwitchImplBase implements IOF13Switch { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 98 | private AtomicBoolean driverHandshakeComplete; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 99 | private AtomicBoolean haltStateMachine; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 100 | private OFFactory factory; |
| 101 | private static final int OFPCML_NO_BUFFER = 0xffff; |
| 102 | // Configuration of asynch messages to controller. We need different |
| 103 | // asynch messages depending on role-equal or role-master. |
| 104 | // We don't want to get anything if we are slave. |
| 105 | private static final long SET_FLOW_REMOVED_MASK_MASTER = 0xf; |
| 106 | private static final long SET_PACKET_IN_MASK_MASTER = 0x7; |
| 107 | private static final long SET_PORT_STATUS_MASK_MASTER = 0x7; |
| 108 | private static final long SET_FLOW_REMOVED_MASK_EQUAL = 0x0; |
| 109 | private static final long SET_PACKET_IN_MASK_EQUAL = 0x0; |
| 110 | private static final long SET_PORT_STATUS_MASK_EQUAL = 0x7; |
| 111 | private static final long SET_ALL_SLAVE = 0x0; |
| 112 | |
| 113 | private static final long TEST_FLOW_REMOVED_MASK = 0xf; |
| 114 | private static final long TEST_PACKET_IN_MASK = 0x7; |
| 115 | private static final long TEST_PORT_STATUS_MASK = 0x7; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 116 | |
| 117 | private static final int TABLE_VLAN = 0; |
| 118 | private static final int TABLE_TMAC = 1; |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 119 | private static final int TABLE_IPv4_UNICAST = 2; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 120 | private static final int TABLE_MPLS = 3; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 121 | private static final int TABLE_ACL = 5; |
| 122 | |
| 123 | private static final short MAX_PRIORITY = (short) 0xffff; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 124 | private static final short PRIORITY_MULTIPLIER = (short) 2046; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 125 | private static final short MIN_PRIORITY = 0x0; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 126 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 127 | private long barrierXidToWaitFor = -1; |
| 128 | private DriverState driverState; |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 129 | private final boolean usePipeline13; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 130 | private SegmentRouterConfig srConfig; |
| 131 | private ConcurrentMap<Dpid, Set<PortNumber>> neighbors; |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 132 | private ConcurrentMap<PortNumber, Dpid> portToNeighbors; |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 133 | private List<Integer> edgeLabels; |
| 134 | private boolean isEdgeRouter; |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 135 | private int sid; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 136 | private ConcurrentMap<NeighborSet, EcmpInfo> ecmpGroups; |
Srikanth Vavilapalli | b95e6e0 | 2014-10-02 13:56:39 -0700 | [diff] [blame] | 137 | private ConcurrentMap<PortNumber, ArrayList<NeighborSet>> portNeighborSetMap; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 138 | |
| 139 | |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 140 | |
| 141 | public OFSwitchImplCPqD13(OFDescStatsReply desc, boolean usePipeline13) { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 142 | super(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 143 | haltStateMachine = new AtomicBoolean(false); |
| 144 | driverState = DriverState.INIT; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 145 | driverHandshakeComplete = new AtomicBoolean(false); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 146 | setSwitchDescription(desc); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 147 | neighbors = new ConcurrentHashMap<Dpid, Set<PortNumber>>(); |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 148 | portToNeighbors = new ConcurrentHashMap<PortNumber, Dpid>(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 149 | ecmpGroups = new ConcurrentHashMap<NeighborSet, EcmpInfo>(); |
Srikanth Vavilapalli | b95e6e0 | 2014-10-02 13:56:39 -0700 | [diff] [blame] | 150 | portNeighborSetMap = |
| 151 | new ConcurrentHashMap<PortNumber, ArrayList<NeighborSet>>(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 152 | edgeLabels = new ArrayList<Integer>(); |
| 153 | isEdgeRouter = false; |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 154 | this.usePipeline13 = usePipeline13; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 157 | // ***************************** |
| 158 | // OFSwitchImplBase |
| 159 | // ***************************** |
| 160 | |
| 161 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 162 | /* (non-Javadoc) |
| 163 | * @see java.lang.Object#toString() |
| 164 | */ |
| 165 | @Override |
| 166 | public String toString() { |
| 167 | return "OFSwitchImplCPqD13 [" + ((channel != null) |
| 168 | ? channel.getRemoteAddress() : "?") |
| 169 | + " DPID[" + ((stringId != null) ? stringId : "?") + "]]"; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public void startDriverHandshake() throws IOException { |
| 174 | log.debug("Starting driver handshake for sw {}", getStringId()); |
| 175 | if (startDriverHandshakeCalled) { |
| 176 | throw new SwitchDriverSubHandshakeAlreadyStarted(); |
| 177 | } |
| 178 | startDriverHandshakeCalled = true; |
Jonathan Hart | a213bce | 2014-08-11 15:44:07 -0700 | [diff] [blame] | 179 | factory = getFactory(); |
Jonathan Hart | cb34f38 | 2014-08-12 21:11:03 -0700 | [diff] [blame] | 180 | if (!usePipeline13) { |
| 181 | // Send packet-in to controller if a packet misses the first table |
| 182 | populateTableMissEntry(0, true, false, false, 0); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 183 | driverHandshakeComplete.set(true); |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 184 | } else { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 185 | nextDriverState(); |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 186 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public boolean isDriverHandshakeComplete() { |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 191 | if (!startDriverHandshakeCalled) |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 192 | throw new SwitchDriverSubHandshakeNotStarted(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 193 | return driverHandshakeComplete.get(); |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | public void processDriverHandshakeMessage(OFMessage m) { |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 198 | if (!startDriverHandshakeCalled) |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 199 | throw new SwitchDriverSubHandshakeNotStarted(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 200 | if (isDriverHandshakeComplete()) |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 201 | throw new SwitchDriverSubHandshakeCompleted(m); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 202 | try { |
| 203 | processOFMessage(this, m); |
| 204 | } catch (IOException e) { |
| 205 | log.error("Error generated when processing OFMessage", e.getCause()); |
| 206 | } |
| 207 | } |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 208 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 209 | @Override |
| 210 | public String getSwitchDriverState() { |
| 211 | return driverState.toString(); |
| 212 | } |
| 213 | |
Srikanth Vavilapalli | bd9b3e2 | 2014-10-02 08:57:46 -0700 | [diff] [blame] | 214 | public void removePortFromGroups(PortNumber port) { |
Srikanth Vavilapalli | cf1840b | 2014-10-09 15:29:51 -0700 | [diff] [blame^] | 215 | /* FIX: removePortFromGroups is not working */ |
| 216 | |
| 217 | /* ArrayList<NeighborSet> portNSSet = portNeighborSetMap.get(port); |
| 218 | if (portNSSet == null) |
| 219 | { |
| 220 | *//* No Groups are created with this port yet */ |
| 221 | /* log.warn("removePortFromGroups: No groups exist with Switch {} port {}", |
| 222 | getStringId(), port); |
| 223 | return; |
Srikanth Vavilapalli | bd9b3e2 | 2014-10-02 08:57:46 -0700 | [diff] [blame] | 224 | } |
Srikanth Vavilapalli | cf1840b | 2014-10-09 15:29:51 -0700 | [diff] [blame^] | 225 | for (NeighborSet ns : portNSSet) { |
| 226 | *//* Delete the first matched bucket */ |
| 227 | /* EcmpInfo portEcmpInfo = ecmpGroups.get(ns); |
| 228 | Iterator<BucketInfo> it = portEcmpInfo.buckets.iterator(); |
| 229 | while (it.hasNext()) { |
| 230 | BucketInfo bucket = it.next(); |
| 231 | if (bucket.outport.equals(port)) { |
| 232 | it.remove(); |
| 233 | } |
| 234 | } |
| 235 | modifyEcmpGroup(portEcmpInfo); |
| 236 | } |
| 237 | *//* Don't delete the entry from portNeighborSetMap because |
| 238 | * when the port is up again this info is needed |
| 239 | */ |
Srikanth Vavilapalli | 7d873fd | 2014-10-04 07:50:57 -0700 | [diff] [blame] | 240 | return; |
Srikanth Vavilapalli | bd9b3e2 | 2014-10-02 08:57:46 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | public void addPortToGroups(PortNumber port) { |
Srikanth Vavilapalli | cf1840b | 2014-10-09 15:29:51 -0700 | [diff] [blame^] | 244 | /* ArrayList<NeighborSet> portNSSet = portNeighborSetMap.get(port); |
| 245 | if (portNSSet == null) { |
| 246 | *//* Unknown Port */ |
| 247 | /* log.warn("addPortToGroups: Switch {} port {} is unknown", |
| 248 | getStringId(), port); |
| 249 | return; |
| 250 | } |
| 251 | Dpid neighborDpid = portToNeighbors.get(port); |
| 252 | for (NeighborSet ns : portNSSet) { |
| 253 | *//* Delete the first matched bucket */ |
| 254 | /* EcmpInfo portEcmpInfo = ecmpGroups.get(ns); |
| 255 | BucketInfo b = new BucketInfo(neighborDpid, |
| 256 | MacAddress.of(srConfig.getRouterMac()), |
| 257 | getNeighborRouterMacAddress(neighborDpid), |
| 258 | port, |
| 259 | ns.getEdgeLabel()); |
| 260 | List<BucketInfo> buckets = portEcmpInfo.buckets; |
| 261 | if (buckets == null) { |
| 262 | buckets = new ArrayList<BucketInfo>(); |
| 263 | buckets.add(b); |
| 264 | portEcmpInfo.buckets = buckets; |
| 265 | } else { |
| 266 | buckets.add(b); |
| 267 | } |
| 268 | modifyEcmpGroup(portEcmpInfo); |
| 269 | } |
| 270 | */return; |
Srikanth Vavilapalli | bd9b3e2 | 2014-10-02 08:57:46 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 273 | // ***************************** |
| 274 | // Driver handshake state-machine |
| 275 | // ***************************** |
| 276 | |
| 277 | enum DriverState { |
| 278 | INIT, |
| 279 | SET_TABLE_MISS_ENTRIES, |
| 280 | SET_TABLE_VLAN_TMAC, |
| 281 | SET_GROUPS, |
| 282 | VERIFY_GROUPS, |
| 283 | SET_ADJACENCY_LABELS, |
| 284 | EXIT |
| 285 | } |
| 286 | |
| 287 | protected void nextDriverState() throws IOException { |
| 288 | DriverState currentState = driverState; |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 289 | if (haltStateMachine.get()) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 290 | return; |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 291 | } |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 292 | switch (currentState) { |
| 293 | case INIT: |
| 294 | driverState = DriverState.SET_TABLE_MISS_ENTRIES; |
| 295 | setTableMissEntries(); |
Saurav Das | d84178f | 2014-09-29 17:48:54 -0700 | [diff] [blame] | 296 | sendHandshakeBarrier(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 297 | break; |
| 298 | case SET_TABLE_MISS_ENTRIES: |
| 299 | driverState = DriverState.SET_TABLE_VLAN_TMAC; |
| 300 | getNetworkConfig(); |
| 301 | populateTableVlan(); |
| 302 | populateTableTMac(); |
Saurav Das | d84178f | 2014-09-29 17:48:54 -0700 | [diff] [blame] | 303 | sendHandshakeBarrier(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 304 | break; |
| 305 | case SET_TABLE_VLAN_TMAC: |
| 306 | driverState = DriverState.SET_GROUPS; |
| 307 | createGroups(); |
Saurav Das | d84178f | 2014-09-29 17:48:54 -0700 | [diff] [blame] | 308 | sendHandshakeBarrier(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 309 | break; |
| 310 | case SET_GROUPS: |
| 311 | driverState = DriverState.VERIFY_GROUPS; |
| 312 | verifyGroups(); |
| 313 | break; |
| 314 | case VERIFY_GROUPS: |
| 315 | driverState = DriverState.SET_ADJACENCY_LABELS; |
| 316 | assignAdjacencyLabels(); |
| 317 | break; |
| 318 | case SET_ADJACENCY_LABELS: |
| 319 | driverState = DriverState.EXIT; |
| 320 | driverHandshakeComplete.set(true); |
| 321 | break; |
| 322 | case EXIT: |
| 323 | default: |
| 324 | driverState = DriverState.EXIT; |
| 325 | log.error("Driver handshake has exited for sw: {}", getStringId()); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | void processOFMessage(IOFSwitch sw, OFMessage m) throws IOException { |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 330 | switch (m.getType()) { |
| 331 | case BARRIER_REPLY: |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 332 | processBarrierReply(m); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 333 | break; |
| 334 | |
| 335 | case ERROR: |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 336 | processErrorMessage(m); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 337 | break; |
| 338 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 339 | case GET_ASYNC_REPLY: |
| 340 | OFAsyncGetReply asrep = (OFAsyncGetReply) m; |
| 341 | decodeAsyncGetReply(asrep); |
| 342 | break; |
| 343 | |
| 344 | case PACKET_IN: |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 345 | // not ready to handle packet-ins |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 346 | break; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 347 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 348 | case QUEUE_GET_CONFIG_REPLY: |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 349 | // not doing queue config yet |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 350 | break; |
| 351 | |
| 352 | case STATS_REPLY: |
| 353 | processStatsReply((OFStatsReply) m); |
| 354 | break; |
| 355 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 356 | case ROLE_REPLY: // channelHandler should handle this |
| 357 | case PORT_STATUS: // channelHandler should handle this |
| 358 | case FEATURES_REPLY: // don't care |
| 359 | case FLOW_REMOVED: // don't care |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 360 | default: |
| 361 | log.debug("Received message {} during switch-driver subhandshake " |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 362 | + "from switch {} ... Ignoring message", m, sw.getStringId()); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | private void processStatsReply(OFStatsReply sr) { |
| 367 | switch (sr.getStatsType()) { |
| 368 | case AGGREGATE: |
| 369 | break; |
| 370 | case DESC: |
| 371 | break; |
| 372 | case EXPERIMENTER: |
| 373 | break; |
| 374 | case FLOW: |
| 375 | break; |
| 376 | case GROUP_DESC: |
| 377 | processGroupDesc((OFGroupDescStatsReply) sr); |
| 378 | break; |
| 379 | case GROUP_FEATURES: |
| 380 | processGroupFeatures((OFGroupFeaturesStatsReply) sr); |
| 381 | break; |
| 382 | case METER_CONFIG: |
| 383 | break; |
| 384 | case METER_FEATURES: |
| 385 | break; |
| 386 | case PORT_DESC: |
| 387 | break; |
| 388 | case TABLE_FEATURES: |
| 389 | break; |
| 390 | default: |
| 391 | break; |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 392 | |
| 393 | } |
| 394 | } |
| 395 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 396 | private void processErrorMessage(OFMessage m) { |
| 397 | log.error("Switch {} Error {} in DriverState", getStringId(), |
| 398 | (OFErrorMsg) m, driverState); |
| 399 | } |
| 400 | |
| 401 | private void processBarrierReply(OFMessage m) throws IOException { |
| 402 | if (m.getXid() == barrierXidToWaitFor) { |
| 403 | // Driver state-machine progresses to the next state. |
| 404 | // If Barrier messages is not received, then eventually |
| 405 | // the ChannelHandler state machine will timeout, and the switch |
| 406 | // will be disconnected. |
| 407 | nextDriverState(); |
| 408 | } else { |
| 409 | log.error("Received incorrect barrier-message xid {} (expected: {}) in " |
| 410 | + "switch-driver state {} for switch {}", m, barrierXidToWaitFor, |
| 411 | driverState, getStringId()); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | private void processGroupDesc(OFGroupDescStatsReply gdsr) { |
| 416 | log.info("Sw: {} Group Desc {}", getStringId(), gdsr); |
| 417 | try { |
| 418 | nextDriverState(); |
| 419 | } catch (IOException e) { |
| 420 | // TODO Auto-generated catch block |
| 421 | e.printStackTrace(); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // ***************************** |
| 426 | // Utility methods |
| 427 | // ***************************** |
| 428 | |
| 429 | void setTableMissEntries() throws IOException { |
| 430 | // set all table-miss-entries |
| 431 | populateTableMissEntry(TABLE_VLAN, true, false, false, -1); |
| 432 | populateTableMissEntry(TABLE_TMAC, true, false, false, -1); |
| 433 | populateTableMissEntry(TABLE_IPv4_UNICAST, false, true, true, |
| 434 | TABLE_ACL); |
| 435 | populateTableMissEntry(TABLE_MPLS, false, true, true, |
| 436 | TABLE_ACL); |
| 437 | populateTableMissEntry(TABLE_ACL, false, false, false, -1); |
| 438 | } |
| 439 | |
Saurav Das | d84178f | 2014-09-29 17:48:54 -0700 | [diff] [blame] | 440 | private void sendHandshakeBarrier() throws IOException { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 441 | long xid = getNextTransactionId(); |
| 442 | barrierXidToWaitFor = xid; |
| 443 | OFBarrierRequest br = getFactory() |
| 444 | .buildBarrierRequest() |
| 445 | .setXid(xid) |
| 446 | .build(); |
| 447 | write(br, null); |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * Adds a table-miss-entry to a pipeline table. |
| 452 | * <p> |
| 453 | * The table-miss-entry can be added with 'write-actions' or |
| 454 | * 'apply-actions'. It can also add a 'goto-table' instruction. By default |
| 455 | * if none of the booleans in the call are set, then the table-miss entry is |
| 456 | * added with no instructions, which means that if a packet hits the |
| 457 | * table-miss-entry, pipeline execution will stop, and the action set |
| 458 | * associated with the packet will be executed. |
| 459 | * |
| 460 | * @param tableToAdd the table to where the table-miss-entry will be added |
| 461 | * @param toControllerNow as an APPLY_ACTION instruction |
| 462 | * @param toControllerWrite as a WRITE_ACTION instruction |
| 463 | * @param toTable as a GOTO_TABLE instruction |
| 464 | * @param tableToSend the table to send as per the GOTO_TABLE instruction it |
| 465 | * needs to be set if 'toTable' is true. Ignored of 'toTable' is |
| 466 | * false. |
| 467 | * @throws IOException |
| 468 | */ |
| 469 | @SuppressWarnings("unchecked") |
| 470 | private void populateTableMissEntry(int tableToAdd, boolean toControllerNow, |
| 471 | boolean toControllerWrite, |
| 472 | boolean toTable, int tableToSend) throws IOException { |
| 473 | OFOxmList oxmList = OFOxmList.EMPTY; |
| 474 | OFMatchV3 match = factory.buildMatchV3() |
| 475 | .setOxmList(oxmList) |
| 476 | .build(); |
| 477 | OFAction outc = factory.actions() |
| 478 | .buildOutput() |
| 479 | .setPort(OFPort.CONTROLLER) |
| 480 | .setMaxLen(OFPCML_NO_BUFFER) |
| 481 | .build(); |
| 482 | List<OFInstruction> instructions = new ArrayList<OFInstruction>(); |
| 483 | if (toControllerNow) { |
| 484 | // table-miss instruction to send to controller immediately |
| 485 | OFInstruction instr = factory.instructions() |
| 486 | .buildApplyActions() |
| 487 | .setActions(Collections.singletonList(outc)) |
| 488 | .build(); |
| 489 | instructions.add(instr); |
| 490 | } |
| 491 | |
| 492 | if (toControllerWrite) { |
| 493 | // table-miss instruction to write-action to send to controller |
| 494 | // this will be executed whenever the action-set gets executed |
| 495 | OFInstruction instr = factory.instructions() |
| 496 | .buildWriteActions() |
| 497 | .setActions(Collections.singletonList(outc)) |
| 498 | .build(); |
| 499 | instructions.add(instr); |
| 500 | } |
| 501 | |
| 502 | if (toTable) { |
| 503 | // table-miss instruction to goto-table x |
| 504 | OFInstruction instr = factory.instructions() |
| 505 | .gotoTable(TableId.of(tableToSend)); |
| 506 | instructions.add(instr); |
| 507 | } |
| 508 | |
| 509 | if (!toControllerNow && !toControllerWrite && !toTable) { |
| 510 | // table-miss has no instruction - at which point action-set will be |
| 511 | // executed - if there is an action to output/group in the action |
| 512 | // set |
| 513 | // the packet will be sent there, otherwise it will be dropped. |
| 514 | instructions = (List<OFInstruction>) Collections.EMPTY_LIST; |
| 515 | } |
| 516 | |
| 517 | OFMessage tableMissEntry = factory.buildFlowAdd() |
| 518 | .setTableId(TableId.of(tableToAdd)) |
| 519 | .setMatch(match) // match everything |
| 520 | .setInstructions(instructions) |
| 521 | .setPriority(MIN_PRIORITY) |
| 522 | .setBufferId(OFBufferId.NO_BUFFER) |
| 523 | .setIdleTimeout(0) |
| 524 | .setHardTimeout(0) |
| 525 | .setXid(getNextTransactionId()) |
| 526 | .build(); |
| 527 | write(tableMissEntry, null); |
| 528 | } |
| 529 | |
| 530 | private void getNetworkConfig() { |
| 531 | INetworkConfigService ncs = floodlightProvider.getNetworkConfigService(); |
| 532 | SwitchConfigStatus scs = ncs.checkSwitchConfig(new Dpid(getId())); |
| 533 | if (scs.getConfigState() == NetworkConfigState.ACCEPT_ADD) { |
| 534 | srConfig = (SegmentRouterConfig) scs.getSwitchConfig(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 535 | isEdgeRouter = srConfig.isEdgeRouter(); |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 536 | sid = srConfig.getNodeSid(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 537 | } else { |
| 538 | log.error("Switch not configured as Segment-Router"); |
| 539 | } |
| 540 | |
| 541 | List<LinkConfig> linkConfigList = ncs.getConfiguredAllowedLinks(); |
| 542 | setNeighbors(linkConfigList); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 543 | |
| 544 | if (isEdgeRouter) { |
| 545 | List<SwitchConfig> switchList = ncs.getConfiguredAllowedSwitches(); |
| 546 | getAllEdgeLabels(switchList); |
| 547 | } |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | private void populateTableVlan() throws IOException { |
| 551 | List<OFMessage> msglist = new ArrayList<OFMessage>(); |
| 552 | for (OFPortDesc p : getPorts()) { |
| 553 | int pnum = p.getPortNo().getPortNumber(); |
| 554 | if (U32.of(pnum).compareTo(U32.of(OFPort.MAX.getPortNumber())) < 1) { |
| 555 | OFOxmInPort oxp = factory.oxms().inPort(p.getPortNo()); |
| 556 | OFOxmVlanVid oxv = factory.oxms() |
| 557 | .vlanVid(OFVlanVidMatch.UNTAGGED); |
| 558 | OFOxmList oxmList = OFOxmList.of(oxp, oxv); |
| 559 | OFMatchV3 match = factory.buildMatchV3() |
| 560 | .setOxmList(oxmList).build(); |
| 561 | |
| 562 | // TODO: match on vlan-tagged packets for vlans configured on |
| 563 | // subnet ports and strip-vlan |
| 564 | |
| 565 | // Do not need to add vlans |
| 566 | /*int vlanid = getVlanConfig(pnum); |
| 567 | OFOxmVlanVid vidToSet = factory.oxms() |
| 568 | .vlanVid(OFVlanVidMatch.ofVlan(vlanid)); |
| 569 | OFAction pushVlan = factory.actions().pushVlan(EthType.VLAN_FRAME); |
| 570 | OFAction setVlan = factory.actions().setField(vidToSet); |
| 571 | List<OFAction> actionlist = new ArrayList<OFAction>(); |
| 572 | actionlist.add(pushVlan); |
| 573 | actionlist.add(setVlan); |
| 574 | OFInstruction appAction = factory.instructions().buildApplyActions() |
| 575 | .setActions(actionlist).build();*/ |
| 576 | |
| 577 | OFInstruction gotoTbl = factory.instructions().buildGotoTable() |
| 578 | .setTableId(TableId.of(TABLE_TMAC)).build(); |
| 579 | List<OFInstruction> instructions = new ArrayList<OFInstruction>(); |
| 580 | // instructions.add(appAction); |
| 581 | instructions.add(gotoTbl); |
| 582 | OFMessage flowEntry = factory.buildFlowAdd() |
| 583 | .setTableId(TableId.of(TABLE_VLAN)) |
| 584 | .setMatch(match) |
| 585 | .setInstructions(instructions) |
| 586 | .setPriority(1000) // does not matter - all rules |
| 587 | // exclusive |
| 588 | .setBufferId(OFBufferId.NO_BUFFER) |
| 589 | .setIdleTimeout(0) |
| 590 | .setHardTimeout(0) |
| 591 | .setXid(getNextTransactionId()) |
| 592 | .build(); |
| 593 | msglist.add(flowEntry); |
| 594 | } |
| 595 | } |
| 596 | write(msglist); |
| 597 | log.debug("Adding {} port/vlan-rules in sw {}", msglist.size(), getStringId()); |
| 598 | } |
| 599 | |
| 600 | private void populateTableTMac() throws IOException { |
| 601 | // match for router-mac and ip-packets |
| 602 | OFOxmEthType oxe = factory.oxms().ethType(EthType.IPv4); |
| 603 | OFOxmEthDst dmac = factory.oxms().ethDst(getRouterMacAddr()); |
| 604 | OFOxmList oxmListIp = OFOxmList.of(dmac, oxe); |
| 605 | OFMatchV3 matchIp = factory.buildMatchV3() |
| 606 | .setOxmList(oxmListIp).build(); |
| 607 | OFInstruction gotoTblIp = factory.instructions().buildGotoTable() |
| 608 | .setTableId(TableId.of(TABLE_IPv4_UNICAST)).build(); |
| 609 | List<OFInstruction> instructionsIp = Collections.singletonList(gotoTblIp); |
| 610 | OFMessage ipEntry = factory.buildFlowAdd() |
| 611 | .setTableId(TableId.of(TABLE_TMAC)) |
| 612 | .setMatch(matchIp) |
| 613 | .setInstructions(instructionsIp) |
| 614 | .setPriority(1000) // strict priority required lower than |
| 615 | // multicastMac |
| 616 | .setBufferId(OFBufferId.NO_BUFFER) |
| 617 | .setIdleTimeout(0) |
| 618 | .setHardTimeout(0) |
| 619 | .setXid(getNextTransactionId()) |
| 620 | .build(); |
| 621 | |
| 622 | // match for router-mac and mpls packets |
| 623 | OFOxmEthType oxmpls = factory.oxms().ethType(EthType.MPLS_UNICAST); |
| 624 | OFOxmList oxmListMpls = OFOxmList.of(dmac, oxmpls); |
| 625 | OFMatchV3 matchMpls = factory.buildMatchV3() |
| 626 | .setOxmList(oxmListMpls).build(); |
| 627 | OFInstruction gotoTblMpls = factory.instructions().buildGotoTable() |
| 628 | .setTableId(TableId.of(TABLE_MPLS)).build(); |
| 629 | List<OFInstruction> instructionsMpls = Collections.singletonList(gotoTblMpls); |
| 630 | OFMessage mplsEntry = factory.buildFlowAdd() |
| 631 | .setTableId(TableId.of(TABLE_TMAC)) |
| 632 | .setMatch(matchMpls) |
| 633 | .setInstructions(instructionsMpls) |
| 634 | .setPriority(1001) // strict priority required lower than |
| 635 | // multicastMac |
| 636 | .setBufferId(OFBufferId.NO_BUFFER) |
| 637 | .setIdleTimeout(0) |
| 638 | .setHardTimeout(0) |
| 639 | .setXid(getNextTransactionId()) |
| 640 | .build(); |
| 641 | |
| 642 | log.debug("Adding termination-mac-rules in sw {}", getStringId()); |
| 643 | List<OFMessage> msglist = new ArrayList<OFMessage>(2); |
| 644 | msglist.add(ipEntry); |
| 645 | msglist.add(mplsEntry); |
| 646 | write(msglist); |
| 647 | } |
| 648 | |
| 649 | private MacAddress getRouterMacAddr() { |
| 650 | if (srConfig != null) { |
| 651 | return MacAddress.of(srConfig.getRouterMac()); |
| 652 | } else { |
| 653 | // return a dummy mac address - it will not be used |
| 654 | return MacAddress.of("00:00:00:00:00:00"); |
| 655 | } |
| 656 | } |
| 657 | |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 658 | private boolean isEdgeRouter(Dpid ndpid) { |
| 659 | INetworkConfigService ncs = floodlightProvider.getNetworkConfigService(); |
| 660 | SwitchConfigStatus scs = ncs.checkSwitchConfig(ndpid); |
| 661 | if (scs.getConfigState() == NetworkConfigState.ACCEPT_ADD) { |
| 662 | return ((SegmentRouterConfig) scs.getSwitchConfig()).isEdgeRouter(); |
| 663 | } else { |
| 664 | // TODO: return false if router not allowed |
| 665 | return false; |
| 666 | } |
| 667 | } |
| 668 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 669 | private MacAddress getNeighborRouterMacAddress(Dpid ndpid) { |
| 670 | INetworkConfigService ncs = floodlightProvider.getNetworkConfigService(); |
| 671 | SwitchConfigStatus scs = ncs.checkSwitchConfig(ndpid); |
| 672 | if (scs.getConfigState() == NetworkConfigState.ACCEPT_ADD) { |
| 673 | return MacAddress.of(((SegmentRouterConfig) scs.getSwitchConfig()) |
| 674 | .getRouterMac()); |
| 675 | } else { |
| 676 | // return a dummy mac address - it will not be used |
| 677 | return MacAddress.of("00:00:00:00:00:00"); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | private void setNeighbors(List<LinkConfig> linkConfigList) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 682 | for (LinkConfig lg : linkConfigList) { |
| 683 | if (!lg.getType().equals(NetworkConfigManager.PKT_LINK)) { |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 684 | continue; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 685 | } |
| 686 | PktLinkConfig plg = (PktLinkConfig) lg; |
| 687 | if (plg.getDpid1() == getId()) { |
| 688 | addNeighborAtPort(new Dpid(plg.getDpid2()), |
| 689 | PortNumber.uint32(plg.getPort1())); |
| 690 | } else if (plg.getDpid2() == getId()) { |
| 691 | addNeighborAtPort(new Dpid(plg.getDpid1()), |
| 692 | PortNumber.uint32(plg.getPort2())); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | private void addNeighborAtPort(Dpid neighborDpid, PortNumber portToNeighbor) { |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 698 | /* Update NeighborToPort database */ |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 699 | if (neighbors.get(neighborDpid) != null) { |
| 700 | neighbors.get(neighborDpid).add(portToNeighbor); |
| 701 | } else { |
| 702 | Set<PortNumber> ports = new HashSet<PortNumber>(); |
| 703 | ports.add(portToNeighbor); |
| 704 | neighbors.put(neighborDpid, ports); |
| 705 | } |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 706 | |
| 707 | /* Update portToNeighbors database */ |
| 708 | if (portToNeighbors.get(portToNeighbor) == null) |
| 709 | portToNeighbors.put(portToNeighbor, neighborDpid); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 712 | private void getAllEdgeLabels(List<SwitchConfig> switchList) { |
| 713 | for (SwitchConfig sc : switchList) { |
| 714 | /* TODO: Do we need to check if the SwitchConfig is of |
| 715 | * type SegmentRouter? |
| 716 | */ |
| 717 | if ((sc.getDpid() == getId()) || |
| 718 | (((SegmentRouterConfig) sc).isEdgeRouter() != true)) { |
| 719 | continue; |
| 720 | } |
| 721 | edgeLabels.add(((SegmentRouterConfig) sc).getNodeSid()); |
| 722 | } |
Srikanth Vavilapalli | ca2263c | 2014-10-09 15:19:11 -0700 | [diff] [blame] | 723 | log.debug("getAllEdgeLabels: Node Labels found {}", edgeLabels); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 726 | private boolean isNodeLabelAndEdgeLabelSame(Dpid dpid, int edgeLabel) { |
| 727 | INetworkConfigService ncs = floodlightProvider.getNetworkConfigService(); |
| 728 | SwitchConfigStatus scs = ncs.checkSwitchConfig(dpid); |
| 729 | if (scs.getConfigState() == NetworkConfigState.ACCEPT_ADD) { |
| 730 | return (((SegmentRouterConfig) scs.getSwitchConfig()). |
| 731 | getNodeSid() == edgeLabel); |
| 732 | } else { |
| 733 | // TODO: return false if router not allowed |
| 734 | return false; |
| 735 | } |
| 736 | } |
| 737 | |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 738 | private Set<Set<Dpid>> getAllNeighborSets(Set<Dpid> neighbors) { |
| 739 | List<Dpid> list = new ArrayList<Dpid>(neighbors); |
| 740 | Set<Set<Dpid>> sets = new HashSet<Set<Dpid>>(); |
| 741 | /* get the number of elements in the neighbors */ |
| 742 | int elements = list.size(); |
| 743 | /* the number of members of a power set is 2^n |
| 744 | * including the empty set |
| 745 | */ |
| 746 | int powerElements = (1 << elements); |
| 747 | |
| 748 | /* run a binary counter for the number of power elements */ |
| 749 | for (long i = 1; i < powerElements; i++) { |
| 750 | Set<Dpid> dpidSubSet = new HashSet<Dpid>(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 751 | for (int j = 0; j < elements; j++) { |
| 752 | if ((i >> j) % 2 == 1) { |
| 753 | dpidSubSet.add(list.get(j)); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 756 | /* NOTE: Avoid any pairings of edge routers only |
| 757 | * at a backbone router */ |
| 758 | boolean avoidEdgeRouterPairing = true; |
| 759 | if ((!isEdgeRouter) && (dpidSubSet.size() > 1)) { |
Srikanth Vavilapalli | 696010f | 2014-10-08 17:00:17 -0700 | [diff] [blame] | 760 | for (Dpid dpid : dpidSubSet) { |
| 761 | if (!isEdgeRouter(dpid)) { |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 762 | avoidEdgeRouterPairing = false; |
Srikanth Vavilapalli | 696010f | 2014-10-08 17:00:17 -0700 | [diff] [blame] | 763 | break; |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | else |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 768 | avoidEdgeRouterPairing = false; |
Srikanth Vavilapalli | 696010f | 2014-10-08 17:00:17 -0700 | [diff] [blame] | 769 | |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 770 | if (!avoidEdgeRouterPairing) |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 771 | sets.add(dpidSubSet); |
| 772 | } |
| 773 | return sets; |
| 774 | } |
| 775 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 776 | /** |
| 777 | * createGroups creates ECMP groups for all ports on this router connected |
| 778 | * to other routers (in the OF network). The information for ports is |
| 779 | * gleaned from the configured links. If no links are configured no groups |
| 780 | * will be created, and it is up to the caller of the IOF13Switch API to |
| 781 | * create groups. |
| 782 | * <p> |
| 783 | * By default all ports connected to the same neighbor router will be part |
| 784 | * of the same ECMP group. In addition, groups will be created for all |
| 785 | * possible combinations of neighbor routers. |
| 786 | * <p> |
| 787 | * For example, consider this router (R0) connected to 3 neighbors (R1, R2, |
| 788 | * and R3). The following groups will be created in R0: |
| 789 | * <li>1) all ports to R1, |
| 790 | * <li>2) all ports to R2, |
| 791 | * <li>3) all ports to R3, |
| 792 | * <li>4) all ports to R1 and R2 |
| 793 | * <li>5) all ports to R1 and R3 |
| 794 | * <li>6) all ports to R2 and R3 |
| 795 | * <li>7) all ports to R1, R2, and R3 |
| 796 | */ |
| 797 | private void createGroups() { |
| 798 | Set<Dpid> dpids = neighbors.keySet(); |
| 799 | if (dpids == null || dpids.isEmpty()) { |
| 800 | return; |
| 801 | } |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 802 | /* Create all possible Neighbor sets from this router |
| 803 | * NOTE: Avoid any pairings of edge routers only |
| 804 | */ |
| 805 | Set<Set<Dpid>> powerSet = getAllNeighborSets(dpids); |
Srikanth Vavilapalli | ca2263c | 2014-10-09 15:19:11 -0700 | [diff] [blame] | 806 | log.debug("The size of neighbor powerset for sw {} is ", |
| 807 | getStringId(), powerSet.size()); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 808 | Set<NeighborSet> nsSet = new HashSet<NeighborSet>(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 809 | for (Set<Dpid> combo : powerSet) { |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 810 | if (combo.isEmpty()) |
| 811 | continue; |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 812 | if (isEdgeRouter && !edgeLabels.isEmpty()) { |
| 813 | for (Integer edgeLabel : edgeLabels) { |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 814 | /* If it is local node's edge label, continue */ |
| 815 | if (edgeLabel == sid) |
| 816 | continue; |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 817 | NeighborSet ns = new NeighborSet(); |
| 818 | ns.addDpids(combo); |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 819 | /* Check if the edge label being set is of the |
| 820 | * same node in the Neighbor set |
| 821 | */ |
| 822 | if ((combo.size() != 1) || |
| 823 | (!isNodeLabelAndEdgeLabelSame( |
| 824 | combo.iterator().next(), edgeLabel))){ |
| 825 | ns.setEdgeLabel(edgeLabel); |
| 826 | } |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 827 | nsSet.add(ns); |
| 828 | } |
| 829 | } else { |
| 830 | NeighborSet ns = new NeighborSet(); |
| 831 | ns.addDpids(combo); |
| 832 | nsSet.add(ns); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 833 | } |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 834 | } |
Srikanth Vavilapalli | ca2263c | 2014-10-09 15:19:11 -0700 | [diff] [blame] | 835 | log.debug("The neighborset with label for sw {} is ", |
| 836 | getStringId(), nsSet); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 837 | |
| 838 | int groupid = 1; |
| 839 | for (NeighborSet ns : nsSet) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 840 | List<BucketInfo> buckets = new ArrayList<BucketInfo>(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 841 | for (Dpid d : ns.getDpids()) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 842 | for (PortNumber sp : neighbors.get(d)) { |
| 843 | BucketInfo b = new BucketInfo(d, |
| 844 | MacAddress.of(srConfig.getRouterMac()), |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 845 | getNeighborRouterMacAddress(d), sp, |
| 846 | ns.getEdgeLabel()); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 847 | buckets.add(b); |
Srikanth Vavilapalli | bd9b3e2 | 2014-10-02 08:57:46 -0700 | [diff] [blame] | 848 | |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 849 | /* Update Port Neighborset map */ |
Srikanth Vavilapalli | bd9b3e2 | 2014-10-02 08:57:46 -0700 | [diff] [blame] | 850 | ArrayList<NeighborSet> portNeighborSets = |
| 851 | portNeighborSetMap.get(sp); |
| 852 | if (portNeighborSets == null) { |
| 853 | portNeighborSets = new ArrayList<NeighborSet>(); |
| 854 | portNeighborSets.add(ns); |
| 855 | portNeighborSetMap.put(sp, portNeighborSets); |
| 856 | } |
| 857 | else |
| 858 | portNeighborSets.add(ns); |
| 859 | } |
| 860 | } |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 861 | EcmpInfo ecmpInfo = new EcmpInfo(groupid++, buckets); |
| 862 | setEcmpGroup(ecmpInfo); |
| 863 | ecmpGroups.put(ns, ecmpInfo); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 864 | log.debug("Creating ecmp group in sw {} for neighbor set {}: {}", |
| 865 | getStringId(), ns, ecmpInfo); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 866 | } |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 867 | |
| 868 | // temp map of ecmp groupings |
| 869 | /* Map<NeighborSet, List<BucketInfo>> temp = |
| 870 | new HashMap<NeighborSet, List<BucketInfo>>(); |
| 871 | */ |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | private class EcmpInfo { |
| 875 | int groupId; |
| 876 | List<BucketInfo> buckets; |
| 877 | |
| 878 | EcmpInfo(int gid, List<BucketInfo> bucketInfos) { |
| 879 | groupId = gid; |
| 880 | buckets = bucketInfos; |
| 881 | } |
| 882 | |
| 883 | @Override |
| 884 | public String toString() { |
| 885 | return "groupId: " + groupId + ", buckets: " + buckets; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | private class BucketInfo { |
| 890 | Dpid neighborDpid; |
| 891 | MacAddress srcMac; |
| 892 | MacAddress dstMac; |
| 893 | PortNumber outport; |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 894 | int mplsLabel; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 895 | |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 896 | BucketInfo(Dpid nDpid, MacAddress smac, MacAddress dmac, |
| 897 | PortNumber p, int label) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 898 | neighborDpid = nDpid; |
| 899 | srcMac = smac; |
| 900 | dstMac = dmac; |
| 901 | outport = p; |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 902 | mplsLabel = label; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | @Override |
| 906 | public String toString() { |
| 907 | return " {neighborDpid: " + neighborDpid + ", dstMac: " + dstMac + |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 908 | ", srcMac: " + srcMac + ", outport: " + outport + |
| 909 | "mplsLabel: " + mplsLabel + "}"; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
| 913 | private void setEcmpGroup(EcmpInfo ecmpInfo) { |
| 914 | List<OFMessage> msglist = new ArrayList<OFMessage>(); |
| 915 | OFGroup group = OFGroup.of(ecmpInfo.groupId); |
| 916 | |
| 917 | List<OFBucket> buckets = new ArrayList<OFBucket>(); |
| 918 | for (BucketInfo b : ecmpInfo.buckets) { |
| 919 | OFOxmEthDst dmac = factory.oxms() |
| 920 | .ethDst(b.dstMac); |
| 921 | OFAction setDA = factory.actions().buildSetField() |
| 922 | .setField(dmac).build(); |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 923 | OFOxmEthSrc smac = factory.oxms() |
| 924 | .ethSrc(b.srcMac); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 925 | OFAction setSA = factory.actions().buildSetField() |
| 926 | .setField(smac).build(); |
| 927 | OFAction outp = factory.actions().buildOutput() |
| 928 | .setPort(OFPort.of(b.outport.shortValue())) |
| 929 | .build(); |
| 930 | List<OFAction> actions = new ArrayList<OFAction>(); |
| 931 | actions.add(setSA); |
| 932 | actions.add(setDA); |
| 933 | actions.add(outp); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 934 | if (b.mplsLabel != -1) { |
| 935 | OFAction pushLabel = factory.actions().buildPushMpls() |
| 936 | .setEthertype(EthType.MPLS_UNICAST).build(); |
Sangho Shin | 62ce5c1 | 2014-10-08 16:24:40 -0700 | [diff] [blame] | 937 | OFOxmMplsLabel lid = factory.oxms() |
| 938 | .mplsLabel(U32.of(b.mplsLabel)); |
| 939 | OFAction setLabel = factory.actions().buildSetField() |
| 940 | .setField(lid).build(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 941 | OFAction copyTtl = factory.actions().copyTtlOut(); |
| 942 | OFAction decrTtl = factory.actions().decMplsTtl(); |
| 943 | actions.add(pushLabel); |
| 944 | actions.add(setLabel); |
| 945 | actions.add(copyTtl); |
| 946 | actions.add(decrTtl); |
| 947 | } |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 948 | OFBucket ofb = factory.buildBucket() |
| 949 | .setWeight(1) |
| 950 | .setActions(actions) |
| 951 | .build(); |
| 952 | buckets.add(ofb); |
| 953 | } |
| 954 | |
| 955 | OFMessage gm = factory.buildGroupAdd() |
| 956 | .setGroup(group) |
| 957 | .setBuckets(buckets) |
| 958 | .setGroupType(OFGroupType.SELECT) |
| 959 | .setXid(getNextTransactionId()) |
| 960 | .build(); |
| 961 | msglist.add(gm); |
| 962 | try { |
| 963 | write(msglist); |
| 964 | } catch (IOException e) { |
| 965 | // TODO Auto-generated catch block |
| 966 | e.printStackTrace(); |
| 967 | } |
| 968 | } |
| 969 | |
Srikanth Vavilapalli | 7d873fd | 2014-10-04 07:50:57 -0700 | [diff] [blame] | 970 | private void modifyEcmpGroup(EcmpInfo ecmpInfo) { |
| 971 | List<OFMessage> msglist = new ArrayList<OFMessage>(); |
| 972 | OFGroup group = OFGroup.of(ecmpInfo.groupId); |
| 973 | |
| 974 | List<OFBucket> buckets = new ArrayList<OFBucket>(); |
| 975 | for (BucketInfo b : ecmpInfo.buckets) { |
| 976 | OFOxmEthDst dmac = factory.oxms() |
| 977 | .ethDst(b.dstMac); |
| 978 | OFAction setDA = factory.actions().buildSetField() |
| 979 | .setField(dmac).build(); |
| 980 | OFOxmEthSrc smac = factory.oxms() |
| 981 | .ethSrc(b.srcMac); |
| 982 | OFAction setSA = factory.actions().buildSetField() |
| 983 | .setField(smac).build(); |
| 984 | OFAction outp = factory.actions().buildOutput() |
| 985 | .setPort(OFPort.of(b.outport.shortValue())) |
| 986 | .build(); |
| 987 | List<OFAction> actions = new ArrayList<OFAction>(); |
| 988 | actions.add(setSA); |
| 989 | actions.add(setDA); |
| 990 | actions.add(outp); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 991 | if (b.mplsLabel != -1) { |
| 992 | OFAction pushLabel = factory.actions().buildPushMpls() |
| 993 | .setEthertype(EthType.MPLS_UNICAST).build(); |
Srikanth Vavilapalli | 4ae146e | 2014-10-09 14:35:26 -0700 | [diff] [blame] | 994 | OFOxmMplsLabel lid = factory.oxms() |
| 995 | .mplsLabel(U32.of(b.mplsLabel)); |
| 996 | OFAction setLabel = factory.actions().buildSetField() |
| 997 | .setField(lid).build(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 998 | OFAction copyTtl = factory.actions().copyTtlOut(); |
| 999 | OFAction decrTtl = factory.actions().decMplsTtl(); |
| 1000 | actions.add(pushLabel); |
| 1001 | actions.add(setLabel); |
| 1002 | actions.add(copyTtl); |
| 1003 | actions.add(decrTtl); |
| 1004 | } |
Srikanth Vavilapalli | 7d873fd | 2014-10-04 07:50:57 -0700 | [diff] [blame] | 1005 | OFBucket ofb = factory.buildBucket() |
| 1006 | .setWeight(1) |
| 1007 | .setActions(actions) |
| 1008 | .build(); |
| 1009 | buckets.add(ofb); |
| 1010 | } |
| 1011 | |
| 1012 | OFMessage gm = factory.buildGroupModify() |
| 1013 | .setGroup(group) |
| 1014 | .setBuckets(buckets) |
| 1015 | .setGroupType(OFGroupType.SELECT) |
| 1016 | .setXid(getNextTransactionId()) |
| 1017 | .build(); |
| 1018 | msglist.add(gm); |
| 1019 | try { |
| 1020 | write(msglist); |
| 1021 | } catch (IOException e) { |
| 1022 | // TODO Auto-generated catch block |
| 1023 | e.printStackTrace(); |
| 1024 | } |
| 1025 | } |
| 1026 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1027 | private void verifyGroups() throws IOException { |
| 1028 | sendGroupDescRequest(); |
| 1029 | } |
| 1030 | |
| 1031 | private void sendGroupDescRequest() throws IOException { |
| 1032 | OFMessage gdr = factory.buildGroupDescStatsRequest() |
| 1033 | .setXid(getNextTransactionId()) |
| 1034 | .build(); |
| 1035 | write(gdr, null); |
| 1036 | } |
| 1037 | |
| 1038 | private void assignAdjacencyLabels() { |
| 1039 | // TODO |
| 1040 | try { |
| 1041 | nextDriverState(); |
| 1042 | } catch (IOException e) { |
| 1043 | // TODO Auto-generated catch block |
| 1044 | e.printStackTrace(); |
| 1045 | } |
| 1046 | } |
| 1047 | |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1048 | private OFAction getOFAction(Action action) { |
| 1049 | OFAction ofAction = null; |
| 1050 | if (action instanceof OutputAction) { |
| 1051 | OutputAction outputAction = (OutputAction) action; |
| 1052 | OFPort port = OFPort.of((int) outputAction.getPortNumber().value()); |
| 1053 | ofAction = factory.actions().output(port, Short.MAX_VALUE); |
| 1054 | } else if (action instanceof ModifyDstMacAction) { |
| 1055 | long dstMac = ((ModifyDstMacAction) action).getDstMac().toLong(); |
| 1056 | OFOxmEthDst dmac = factory.oxms() |
| 1057 | .ethDst(MacAddress.of(dstMac)); |
| 1058 | ofAction = factory.actions().buildSetField() |
| 1059 | .setField(dmac).build(); |
| 1060 | } else if (action instanceof ModifySrcMacAction) { |
| 1061 | long srcMac = ((ModifySrcMacAction) action).getSrcMac().toLong(); |
| 1062 | OFOxmEthSrc smac = factory.oxms() |
| 1063 | .ethSrc(MacAddress.of(srcMac)); |
| 1064 | ofAction = factory.actions().buildSetField() |
| 1065 | .setField(smac).build(); |
Srikanth Vavilapalli | 6814430 | 2014-10-08 15:55:24 -0700 | [diff] [blame] | 1066 | /*} else if (action instanceof PushMplsAction) { |
| 1067 | ofAction = factory.actions().pushMpls(EthType.MPLS_UNICAST); |
| 1068 | } else if (action instanceof SetMplsIdAction) { |
| 1069 | int labelid = ((SetMplsIdAction) action).getMplsId(); |
| 1070 | OFOxmMplsLabel lid = factory.oxms() |
| 1071 | .mplsLabel(U32.of(labelid)); |
| 1072 | ofAction = factory.actions().buildSetField() |
| 1073 | .setField(lid).build(); |
| 1074 | */} else if (action instanceof PopMplsAction) { |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1075 | EthType ethertype = ((PopMplsAction) action).getEthType(); |
| 1076 | ofAction = factory.actions().popMpls(ethertype); |
| 1077 | } else if (action instanceof GroupAction) { |
| 1078 | NeighborSet ns = ((GroupAction) action).getDpids(); |
| 1079 | EcmpInfo ei = ecmpGroups.get(ns); |
| 1080 | if (ei != null) { |
| 1081 | int gid = ei.groupId; |
| 1082 | ofAction = factory.actions().buildGroup() |
| 1083 | .setGroup(OFGroup.of(gid)) |
| 1084 | .build(); |
| 1085 | } else { |
| 1086 | log.error("Unable to find ecmp group for neighbors {} at " |
| 1087 | + "switch {}", ns, getStringId()); |
| 1088 | } |
| 1089 | } else if (action instanceof DecNwTtlAction) { |
| 1090 | ofAction = factory.actions().decNwTtl(); |
| 1091 | } else if (action instanceof DecMplsTtlAction) { |
| 1092 | ofAction = factory.actions().decMplsTtl(); |
| 1093 | } else if (action instanceof CopyTtlInAction) { |
| 1094 | ofAction = factory.actions().copyTtlIn(); |
| 1095 | } else if (action instanceof CopyTtlOutAction) { |
| 1096 | ofAction = factory.actions().copyTtlOut(); |
| 1097 | } else { |
| 1098 | log.warn("Unsupported Action type: {}", action.getClass().getName()); |
| 1099 | return null; |
| 1100 | } |
| 1101 | |
| 1102 | // not supported by loxigen |
| 1103 | // OFAction setBos = |
| 1104 | // factory.actions().buildSetField().setField(bos).build(); |
| 1105 | |
| 1106 | return ofAction; |
| 1107 | } |
| 1108 | |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1109 | private OFMessage getIpEntry(MatchActionOperationEntry mao) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1110 | MatchAction ma = mao.getTarget(); |
| 1111 | Operator op = mao.getOperator(); |
| 1112 | Ipv4Match ipm = (Ipv4Match) ma.getMatch(); |
| 1113 | |
| 1114 | // set match |
| 1115 | IPv4Net ipdst = ipm.getDestination(); |
| 1116 | OFOxmEthType ethTypeIp = factory.oxms() |
| 1117 | .ethType(EthType.IPv4); |
| 1118 | OFOxmIpv4DstMasked ipPrefix = factory.oxms() |
| 1119 | .ipv4DstMasked( |
| 1120 | IPv4Address.of(ipdst.address().value()), |
| 1121 | IPv4Address.ofCidrMaskLength(ipdst.prefixLen()) |
| 1122 | ); |
| 1123 | OFOxmList oxmList = OFOxmList.of(ethTypeIp, ipPrefix); |
| 1124 | OFMatchV3 match = factory.buildMatchV3() |
| 1125 | .setOxmList(oxmList).build(); |
| 1126 | |
| 1127 | // set actions |
| 1128 | List<OFAction> writeActions = new ArrayList<OFAction>(); |
| 1129 | for (Action action : ma.getActions()) { |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1130 | OFAction ofAction = getOFAction(action); |
| 1131 | if (ofAction != null) { |
| 1132 | writeActions.add(ofAction); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1133 | } |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1136 | // set instructions |
| 1137 | OFInstruction writeInstr = factory.instructions().buildWriteActions() |
| 1138 | .setActions(writeActions).build(); |
| 1139 | OFInstruction gotoInstr = factory.instructions().buildGotoTable() |
| 1140 | .setTableId(TableId.of(TABLE_ACL)).build(); |
| 1141 | List<OFInstruction> instructions = new ArrayList<OFInstruction>(); |
| 1142 | instructions.add(writeInstr); |
| 1143 | instructions.add(gotoInstr); |
| 1144 | |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1145 | // set flow priority to emulate longest prefix match |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1146 | int priority = ipdst.prefixLen() * PRIORITY_MULTIPLIER; |
| 1147 | if (ipdst.prefixLen() == (short) 32) { |
| 1148 | priority = MAX_PRIORITY; |
| 1149 | } |
| 1150 | |
Saurav Das | bc594a4 | 2014-09-25 20:13:50 -0700 | [diff] [blame] | 1151 | // set flow-mod |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1152 | OFFlowMod.Builder fmBuilder = null; |
| 1153 | switch (op) { |
| 1154 | case ADD: |
| 1155 | fmBuilder = factory.buildFlowAdd(); |
| 1156 | break; |
| 1157 | case REMOVE: |
| 1158 | fmBuilder = factory.buildFlowDeleteStrict(); |
| 1159 | break; |
Sangho Shin | 5be3e53 | 2014-10-03 17:20:58 -0700 | [diff] [blame] | 1160 | case MODIFY: // TODO |
| 1161 | fmBuilder = factory.buildFlowModifyStrict(); |
| 1162 | break; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1163 | default: |
| 1164 | log.warn("Unsupported MatchAction Operator: {}", op); |
| 1165 | return null; |
Saurav Das | bc594a4 | 2014-09-25 20:13:50 -0700 | [diff] [blame] | 1166 | } |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1167 | OFMessage ipFlow = fmBuilder |
| 1168 | .setTableId(TableId.of(TABLE_IPv4_UNICAST)) |
| 1169 | .setMatch(match) |
| 1170 | .setInstructions(instructions) |
| 1171 | .setPriority(priority) |
| 1172 | .setBufferId(OFBufferId.NO_BUFFER) |
| 1173 | .setIdleTimeout(0) |
| 1174 | .setHardTimeout(0) |
| 1175 | .setXid(getNextTransactionId()) |
| 1176 | .build(); |
Saurav Das | bc594a4 | 2014-09-25 20:13:50 -0700 | [diff] [blame] | 1177 | log.debug("{} ip-rule {}-{} in sw {}", |
| 1178 | (op == MatchActionOperations.Operator.ADD) ? "Adding" : "Deleting", |
| 1179 | match, writeActions, |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1180 | getStringId()); |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1181 | return ipFlow; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1182 | } |
| 1183 | |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1184 | private OFMessage getMplsEntry(MatchActionOperationEntry mao) { |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1185 | MatchAction ma = mao.getTarget(); |
| 1186 | Operator op = mao.getOperator(); |
| 1187 | MplsMatch mplsm = (MplsMatch) ma.getMatch(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1188 | |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1189 | // set match |
| 1190 | OFOxmEthType ethTypeMpls = factory.oxms() |
| 1191 | .ethType(EthType.MPLS_UNICAST); |
| 1192 | OFOxmMplsLabel labelid = factory.oxms() |
| 1193 | .mplsLabel(U32.of(mplsm.getMplsLabel())); |
| 1194 | OFOxmList oxmList = OFOxmList.of(ethTypeMpls, labelid); |
| 1195 | OFMatchV3 matchlabel = factory.buildMatchV3() |
| 1196 | .setOxmList(oxmList).build(); |
| 1197 | |
| 1198 | // set actions |
| 1199 | List<OFAction> writeActions = new ArrayList<OFAction>(); |
| 1200 | for (Action action : ma.getActions()) { |
| 1201 | OFAction ofAction = getOFAction(action); |
| 1202 | if (ofAction != null) { |
| 1203 | writeActions.add(ofAction); |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | // set instructions |
| 1208 | OFInstruction writeInstr = factory.instructions().buildWriteActions() |
| 1209 | .setActions(writeActions).build(); |
| 1210 | OFInstruction gotoInstr = factory.instructions().buildGotoTable() |
| 1211 | .setTableId(TableId.of(TABLE_ACL)).build(); |
| 1212 | List<OFInstruction> instructions = new ArrayList<OFInstruction>(); |
| 1213 | instructions.add(writeInstr); |
| 1214 | instructions.add(gotoInstr); |
| 1215 | |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1216 | // set flow-mod |
| 1217 | OFFlowMod.Builder fmBuilder = null; |
| 1218 | switch (op) { |
| 1219 | case ADD: |
| 1220 | fmBuilder = factory.buildFlowAdd(); |
| 1221 | break; |
| 1222 | case REMOVE: |
| 1223 | fmBuilder = factory.buildFlowDeleteStrict(); |
| 1224 | break; |
Sangho Shin | 5be3e53 | 2014-10-03 17:20:58 -0700 | [diff] [blame] | 1225 | case MODIFY: // TODO |
| 1226 | fmBuilder = factory.buildFlowModifyStrict(); |
| 1227 | break; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1228 | default: |
| 1229 | log.warn("Unsupported MatchAction Operator: {}", op); |
| 1230 | return null; |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1231 | } |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1232 | |
| 1233 | OFMessage mplsFlow = fmBuilder |
| 1234 | .setTableId(TableId.of(TABLE_MPLS)) |
| 1235 | .setMatch(matchlabel) |
| 1236 | .setInstructions(instructions) |
| 1237 | .setPriority(MAX_PRIORITY) // exact match and exclusive |
| 1238 | .setBufferId(OFBufferId.NO_BUFFER) |
| 1239 | .setIdleTimeout(0) |
| 1240 | .setHardTimeout(0) |
| 1241 | .setXid(getNextTransactionId()) |
| 1242 | .build(); |
Saurav Das | 1cd1015 | 2014-09-26 09:38:07 -0700 | [diff] [blame] | 1243 | log.debug("{} mpls-rule {}-{} in sw {}", |
| 1244 | (op == MatchActionOperations.Operator.ADD) ? "Adding" : "Deleting", |
| 1245 | matchlabel, writeActions, |
| 1246 | getStringId()); |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1247 | return mplsFlow; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1250 | private OFMessage getAclEntry(MatchActionOperationEntry mao) { |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1251 | MatchAction ma = mao.getTarget(); |
| 1252 | Operator op = mao.getOperator(); |
| 1253 | PacketMatch packetMatch = (PacketMatch) ma.getMatch(); |
| 1254 | Builder matchBuilder = factory.buildMatch(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1255 | |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1256 | // set match |
| 1257 | int inport = 0; |
| 1258 | if (ma.getSwitchPort() != null) { |
| 1259 | inport = (int) ma.getSwitchPort().getPortNumber().value(); |
| 1260 | } |
| 1261 | final MACAddress srcMac = packetMatch.getSrcMacAddress(); |
| 1262 | final MACAddress dstMac = packetMatch.getDstMacAddress(); |
| 1263 | final Short etherType = packetMatch.getEtherType(); |
| 1264 | final IPv4Net srcIp = packetMatch.getSrcIpAddress(); |
| 1265 | final IPv4Net dstIp = packetMatch.getDstIpAddress(); |
| 1266 | final Byte ipProto = packetMatch.getIpProtocolNumber(); |
| 1267 | final Short srcTcpPort = packetMatch.getSrcTcpPortNumber(); |
| 1268 | final Short dstTcpPort = packetMatch.getDstTcpPortNumber(); |
| 1269 | if (inport > 0) { |
| 1270 | matchBuilder.setExact(MatchField.IN_PORT, |
| 1271 | OFPort.of(inport)); |
| 1272 | } |
| 1273 | if (srcMac != null) { |
| 1274 | matchBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(srcMac.toLong())); |
| 1275 | } |
| 1276 | if (dstMac != null) { |
| 1277 | matchBuilder.setExact(MatchField.ETH_DST, MacAddress.of(dstMac.toLong())); |
| 1278 | } |
| 1279 | if (etherType != null) { |
| 1280 | matchBuilder.setExact(MatchField.ETH_TYPE, EthType.of(etherType)); |
| 1281 | } |
| 1282 | if (srcIp != null) { |
| 1283 | matchBuilder.setMasked(MatchField.IPV4_SRC, |
| 1284 | IPv4Address.of(srcIp.address().value()) |
| 1285 | .withMaskOfLength(srcIp.prefixLen())); |
| 1286 | } |
| 1287 | if (dstIp != null) { |
| 1288 | matchBuilder.setMasked(MatchField.IPV4_DST, |
| 1289 | IPv4Address.of(dstIp.address().value()) |
| 1290 | .withMaskOfLength(dstIp.prefixLen())); |
| 1291 | } |
| 1292 | if (ipProto != null) { |
| 1293 | matchBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(ipProto)); |
| 1294 | } |
| 1295 | if (srcTcpPort != null) { |
| 1296 | matchBuilder.setExact(MatchField.TCP_SRC, TransportPort.of(srcTcpPort)); |
| 1297 | } |
| 1298 | if (dstTcpPort != null) { |
| 1299 | matchBuilder.setExact(MatchField.TCP_DST, TransportPort.of(dstTcpPort)); |
| 1300 | } |
| 1301 | |
| 1302 | // set actions |
| 1303 | List<OFAction> applyActions = new ArrayList<OFAction>(); |
| 1304 | for (Action action : ma.getActions()) { |
| 1305 | OFAction ofAction = getOFAction(action); |
| 1306 | if (ofAction != null) { |
| 1307 | applyActions.add(ofAction); |
| 1308 | } |
| 1309 | } |
| 1310 | |
| 1311 | // set instructions |
| 1312 | OFInstruction clearInstr = factory.instructions().clearActions(); |
| 1313 | OFInstruction applyInstr = factory.instructions().buildApplyActions() |
| 1314 | .setActions(applyActions).build(); |
| 1315 | List<OFInstruction> instructions = new ArrayList<OFInstruction>(); |
| 1316 | instructions.add(clearInstr); |
| 1317 | instructions.add(applyInstr); |
| 1318 | |
| 1319 | // set flow-mod |
| 1320 | OFFlowMod.Builder fmBuilder = null; |
| 1321 | switch (op) { |
| 1322 | case ADD: |
| 1323 | fmBuilder = factory.buildFlowAdd(); |
| 1324 | break; |
| 1325 | case REMOVE: |
| 1326 | fmBuilder = factory.buildFlowDeleteStrict(); |
| 1327 | break; |
Sangho Shin | 5be3e53 | 2014-10-03 17:20:58 -0700 | [diff] [blame] | 1328 | case MODIFY: // TODO |
| 1329 | fmBuilder = factory.buildFlowModifyStrict(); |
| 1330 | break; |
Saurav Das | e972b3a | 2014-09-26 15:41:06 -0700 | [diff] [blame] | 1331 | default: |
| 1332 | log.warn("Unsupported MatchAction Operator: {}", op); |
| 1333 | return null; |
| 1334 | } |
| 1335 | |
| 1336 | OFMessage aclFlow = fmBuilder |
| 1337 | .setTableId(TableId.of(TABLE_ACL)) |
| 1338 | .setMatch(matchBuilder.build()) |
| 1339 | .setInstructions(instructions) |
| 1340 | .setPriority(MAX_PRIORITY / 2) // TODO: wrong - should be MA |
| 1341 | // priority |
| 1342 | .setBufferId(OFBufferId.NO_BUFFER) |
| 1343 | .setIdleTimeout(0) |
| 1344 | .setHardTimeout(0) |
| 1345 | .setXid(getNextTransactionId()) |
| 1346 | .build(); |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1347 | return aclFlow; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | // ***************************** |
| 1351 | // IOF13Switch |
| 1352 | // ***************************** |
| 1353 | |
| 1354 | @Override |
| 1355 | public void pushFlow(MatchActionOperationEntry matchActionOp) throws IOException { |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1356 | OFMessage ofm = getFlow(matchActionOp); |
| 1357 | if (ofm != null) { |
| 1358 | write(Collections.singletonList(ofm)); |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | private OFMessage getFlow(MatchActionOperationEntry matchActionOp) { |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1363 | final MatchAction matchAction = matchActionOp.getTarget(); |
| 1364 | final Match match = matchAction.getMatch(); |
| 1365 | if (match instanceof Ipv4Match) { |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1366 | return getIpEntry(matchActionOp); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1367 | } else if (match instanceof MplsMatch) { |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1368 | return getMplsEntry(matchActionOp); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1369 | } else if (match instanceof PacketMatch) { |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1370 | return getAclEntry(matchActionOp); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1371 | } else { |
| 1372 | log.error("Unknown match type {} pushed to switch {}", match, |
| 1373 | getStringId()); |
| 1374 | } |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1375 | return null; |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | @Override |
| 1379 | public void pushFlows(Collection<MatchActionOperationEntry> matchActionOps) |
| 1380 | throws IOException { |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1381 | List<OFMessage> flowMods = new ArrayList<OFMessage>(); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1382 | for (MatchActionOperationEntry matchActionOp : matchActionOps) { |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1383 | OFMessage ofm = getFlow(matchActionOp); |
| 1384 | if (ofm != null) { |
| 1385 | flowMods.add(ofm); |
| 1386 | } |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1387 | } |
Saurav Das | 0a344b0 | 2014-09-26 14:18:52 -0700 | [diff] [blame] | 1388 | write(flowMods); |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | @Override |
| 1392 | public int getEcmpGroupId(NeighborSet ns) { |
| 1393 | EcmpInfo ei = ecmpGroups.get(ns); |
| 1394 | if (ei == null) { |
| 1395 | return -1; |
| 1396 | } else { |
| 1397 | return ei.groupId; |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | // ***************************** |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 1402 | // Unused |
Saurav Das | fc5e3eb | 2014-09-25 19:05:21 -0700 | [diff] [blame] | 1403 | // ***************************** |
| 1404 | |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 1405 | @SuppressWarnings("unused") |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1406 | private void setAsyncConfig() throws IOException { |
| 1407 | List<OFMessage> msglist = new ArrayList<OFMessage>(3); |
| 1408 | OFMessage setAC = null; |
| 1409 | |
| 1410 | if (role == Role.MASTER) { |
| 1411 | setAC = factory.buildAsyncSet() |
| 1412 | .setFlowRemovedMaskEqualMaster(SET_FLOW_REMOVED_MASK_MASTER) |
| 1413 | .setPacketInMaskEqualMaster(SET_PACKET_IN_MASK_MASTER) |
| 1414 | .setPortStatusMaskEqualMaster(SET_PORT_STATUS_MASK_MASTER) |
| 1415 | .setFlowRemovedMaskSlave(SET_ALL_SLAVE) |
| 1416 | .setPacketInMaskSlave(SET_ALL_SLAVE) |
| 1417 | .setPortStatusMaskSlave(SET_ALL_SLAVE) |
| 1418 | .setXid(getNextTransactionId()) |
| 1419 | .build(); |
| 1420 | } else if (role == Role.EQUAL) { |
| 1421 | setAC = factory.buildAsyncSet() |
| 1422 | .setFlowRemovedMaskEqualMaster(SET_FLOW_REMOVED_MASK_EQUAL) |
| 1423 | .setPacketInMaskEqualMaster(SET_PACKET_IN_MASK_EQUAL) |
| 1424 | .setPortStatusMaskEqualMaster(SET_PORT_STATUS_MASK_EQUAL) |
| 1425 | .setFlowRemovedMaskSlave(SET_ALL_SLAVE) |
| 1426 | .setPacketInMaskSlave(SET_ALL_SLAVE) |
| 1427 | .setPortStatusMaskSlave(SET_ALL_SLAVE) |
| 1428 | .setXid(getNextTransactionId()) |
| 1429 | .build(); |
| 1430 | } |
| 1431 | msglist.add(setAC); |
| 1432 | |
| 1433 | OFMessage br = factory.buildBarrierRequest() |
| 1434 | .setXid(getNextTransactionId()) |
| 1435 | .build(); |
| 1436 | msglist.add(br); |
| 1437 | |
| 1438 | OFMessage getAC = factory.buildAsyncGetRequest() |
| 1439 | .setXid(getNextTransactionId()) |
| 1440 | .build(); |
| 1441 | msglist.add(getAC); |
| 1442 | |
| 1443 | write(msglist); |
| 1444 | } |
| 1445 | |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 1446 | @SuppressWarnings("unused") |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1447 | private void decodeAsyncGetReply(OFAsyncGetReply rep) { |
| 1448 | long frm = rep.getFlowRemovedMaskEqualMaster(); |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 1449 | long frs = rep.getFlowRemovedMaskSlave(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1450 | long pim = rep.getPacketInMaskEqualMaster(); |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 1451 | long pis = rep.getPacketInMaskSlave(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1452 | long psm = rep.getPortStatusMaskEqualMaster(); |
Sangho Shin | 01bca86 | 2014-09-12 11:18:59 -0700 | [diff] [blame] | 1453 | long pss = rep.getPortStatusMaskSlave(); |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1454 | |
| 1455 | if (role == Role.MASTER || role == Role.EQUAL) { // should separate |
| 1456 | log.info("FRM:{}", HexString.toHexString((frm & TEST_FLOW_REMOVED_MASK))); |
| 1457 | log.info("PIM:{}", HexString.toHexString((pim & TEST_PACKET_IN_MASK))); |
| 1458 | log.info("PSM:{}", HexString.toHexString((psm & TEST_PORT_STATUS_MASK))); |
| 1459 | } |
| 1460 | |
| 1461 | } |
| 1462 | |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 1463 | @SuppressWarnings("unused") |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1464 | private void getTableFeatures() throws IOException { |
| 1465 | OFMessage gtf = factory.buildTableFeaturesStatsRequest() |
| 1466 | .setXid(getNextTransactionId()) |
| 1467 | .build(); |
| 1468 | write(gtf, null); |
| 1469 | } |
| 1470 | |
Saurav Das | 80d1739 | 2014-10-01 10:24:56 -0700 | [diff] [blame] | 1471 | @SuppressWarnings("unused") |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1472 | private void sendGroupFeaturesRequest() throws IOException { |
| 1473 | OFMessage gfr = factory.buildGroupFeaturesStatsRequest() |
| 1474 | .setXid(getNextTransactionId()) |
| 1475 | .build(); |
| 1476 | write(gfr, null); |
| 1477 | } |
| 1478 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1479 | private void processGroupFeatures(OFGroupFeaturesStatsReply gfsr) { |
| 1480 | log.info("Sw: {} Group Features {}", getStringId(), gfsr); |
| 1481 | } |
| 1482 | |
Fahad Naeem Khan | d563af6 | 2014-10-08 17:37:25 -0700 | [diff] [blame] | 1483 | @Override |
| 1484 | public TableId getTableId(String tableType) { |
| 1485 | tableType = tableType.toLowerCase(); |
| 1486 | if(tableType.contentEquals("ip")){ |
| 1487 | return TableId.of(OFSwitchImplCPqD13.TABLE_IPv4_UNICAST); |
| 1488 | } |
| 1489 | else if (tableType.contentEquals("mpls")){ |
| 1490 | return TableId.of(OFSwitchImplCPqD13.TABLE_MPLS); |
| 1491 | } |
| 1492 | else if (tableType.contentEquals("acl")){ |
| 1493 | return TableId.of(OFSwitchImplCPqD13.TABLE_ACL); |
| 1494 | } |
| 1495 | else{ |
| 1496 | log.warn("Invalid tableType: {}", tableType); |
| 1497 | return null; |
| 1498 | } |
| 1499 | } |
| 1500 | |
Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1501 | } |