Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
| 3 | import java.util.HashSet; |
| 4 | import java.util.Set; |
| 5 | |
| 6 | import net.floodlightcontroller.util.MACAddress; |
| 7 | import net.onrc.onos.ofcontroller.networkgraph.Port; |
| 8 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame^] | 9 | import net.onrc.onos.ofcontroller.util.Dpid; |
| 10 | import net.onrc.onos.ofcontroller.util.FlowEntryActions; |
| 11 | import net.onrc.onos.ofcontroller.util.FlowEntryId; |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * |
| 15 | * @author Brian O'Connor <bocon@onlab.us> |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | public class FlowEntry { |
| 20 | protected Switch sw; |
| 21 | protected Match match; |
| 22 | protected Set<Action> actions; |
| 23 | |
| 24 | public FlowEntry(Switch sw, Port srcPort, Port dstPort, |
| 25 | MACAddress srcMac, MACAddress dstMac) { |
| 26 | this.sw = sw; |
| 27 | this.match = new Match(sw, srcPort, srcMac, dstMac); |
| 28 | this.actions = new HashSet<Action>(); |
| 29 | this.actions.add(new ForwardAction(dstPort)); |
| 30 | } |
| 31 | |
| 32 | public String toString() { |
| 33 | return match + "->" + actions; |
| 34 | } |
Brian O'Connor | 67c6e66 | 2014-02-17 15:20:44 -0800 | [diff] [blame^] | 35 | |
| 36 | public Switch getSwitch() { |
| 37 | return sw; |
| 38 | } |
| 39 | |
| 40 | public net.onrc.onos.ofcontroller.util.FlowEntry getFlowEntry() { |
| 41 | net.onrc.onos.ofcontroller.util.FlowEntry entry = new net.onrc.onos.ofcontroller.util.FlowEntry(); |
| 42 | entry.setDpid(new Dpid(sw.getDpid())); |
| 43 | entry.setFlowEntryId(new FlowEntryId(0)); // all zero for now |
| 44 | entry.setFlowEntryMatch(match.getFlowEntryMatch()); |
| 45 | FlowEntryActions flowEntryActions = new FlowEntryActions(); |
| 46 | for(Action action : actions) { |
| 47 | flowEntryActions.addAction(action.getFlowEntryAction()); |
| 48 | } |
| 49 | entry.setFlowEntryActions(flowEntryActions); |
| 50 | return entry; |
| 51 | } |
Brian O'Connor | 7f8e301 | 2014-02-15 23:59:29 -0800 | [diff] [blame] | 52 | } |