Showing
8 changed files
with
398 additions
and
16 deletions
| ... | @@ -7,6 +7,8 @@ | ... | @@ -7,6 +7,8 @@ |
| 7 | description="ONOS 3rd party dependencies"> | 7 | description="ONOS 3rd party dependencies"> |
| 8 | <bundle>mvn:commons-lang/commons-lang/2.6</bundle> | 8 | <bundle>mvn:commons-lang/commons-lang/2.6</bundle> |
| 9 | <bundle>mvn:com.google.guava/guava/18.0</bundle> | 9 | <bundle>mvn:com.google.guava/guava/18.0</bundle> |
| 10 | + | ||
| 11 | + <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> | ||
| 10 | </feature> | 12 | </feature> |
| 11 | 13 | ||
| 12 | <feature name="onos-thirdparty-web" version="1.0.0" | 14 | <feature name="onos-thirdparty-web" version="1.0.0" |
| ... | @@ -18,6 +20,7 @@ | ... | @@ -18,6 +20,7 @@ |
| 18 | <bundle>mvn:com.sun.jersey/jersey-core/1.18.1</bundle> | 20 | <bundle>mvn:com.sun.jersey/jersey-core/1.18.1</bundle> |
| 19 | <bundle>mvn:com.sun.jersey/jersey-server/1.18.1</bundle> | 21 | <bundle>mvn:com.sun.jersey/jersey-server/1.18.1</bundle> |
| 20 | <bundle>mvn:com.sun.jersey/jersey-servlet/1.18.1</bundle> | 22 | <bundle>mvn:com.sun.jersey/jersey-servlet/1.18.1</bundle> |
| 23 | + | ||
| 21 | </feature> | 24 | </feature> |
| 22 | 25 | ||
| 23 | <feature name="onos-api" version="1.0.0" | 26 | <feature name="onos-api" version="1.0.0" |
| ... | @@ -60,7 +63,6 @@ | ... | @@ -60,7 +63,6 @@ |
| 60 | <feature name="onos-openflow" version="1.0.0" | 63 | <feature name="onos-openflow" version="1.0.0" |
| 61 | description="ONOS OpenFlow API, Controller & Providers"> | 64 | description="ONOS OpenFlow API, Controller & Providers"> |
| 62 | <feature>onos-api</feature> | 65 | <feature>onos-api</feature> |
| 63 | - <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> | ||
| 64 | 66 | ||
| 65 | <bundle>mvn:org.onlab.onos/onos-of-api/1.0.0-SNAPSHOT</bundle> | 67 | <bundle>mvn:org.onlab.onos/onos-of-api/1.0.0-SNAPSHOT</bundle> |
| 66 | <bundle>mvn:org.onlab.onos/onos-of-ctl/1.0.0-SNAPSHOT</bundle> | 68 | <bundle>mvn:org.onlab.onos/onos-of-ctl/1.0.0-SNAPSHOT</bundle> | ... | ... |
| ... | @@ -78,6 +78,20 @@ public interface OpenFlowController { | ... | @@ -78,6 +78,20 @@ public interface OpenFlowController { |
| 78 | public void removePacketListener(PacketListener listener); | 78 | public void removePacketListener(PacketListener listener); |
| 79 | 79 | ||
| 80 | /** | 80 | /** |
| 81 | + * Register a listener for OF msg events. | ||
| 82 | + * | ||
| 83 | + * @param listener the listener to notify | ||
| 84 | + */ | ||
| 85 | + public void addEventListener(OpenFlowEventListener listener); | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Unregister a listener. | ||
| 89 | + * | ||
| 90 | + * @param listener the listener to unregister | ||
| 91 | + */ | ||
| 92 | + public void removeEventListener(OpenFlowEventListener listener); | ||
| 93 | + | ||
| 94 | + /** | ||
| 81 | * Send a message to a particular switch. | 95 | * Send a message to a particular switch. |
| 82 | * @param dpid the switch to send to. | 96 | * @param dpid the switch to send to. |
| 83 | * @param msg the message to send | 97 | * @param msg the message to send | ... | ... |
| 1 | +package org.onlab.onos.openflow.controller; | ||
| 2 | + | ||
| 3 | +import org.projectfloodlight.openflow.protocol.OFMessage; | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * Notifies providers about openflow msg events. | ||
| 8 | + */ | ||
| 9 | +public interface OpenFlowEventListener { | ||
| 10 | + | ||
| 11 | + /** | ||
| 12 | + * Handles the message event. | ||
| 13 | + * | ||
| 14 | + * @param msg the message | ||
| 15 | + */ | ||
| 16 | + public void handleMessage(Dpid dpid, OFMessage msg); | ||
| 17 | +} |
| ... | @@ -63,4 +63,16 @@ public class OpenflowControllerAdapter implements OpenFlowController { | ... | @@ -63,4 +63,16 @@ public class OpenflowControllerAdapter implements OpenFlowController { |
| 63 | @Override | 63 | @Override |
| 64 | public void setRole(Dpid dpid, RoleState role) { | 64 | public void setRole(Dpid dpid, RoleState role) { |
| 65 | } | 65 | } |
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public void addEventListener(OpenFlowEventListener listener) { | ||
| 69 | + // TODO Auto-generated method stub | ||
| 70 | + | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @Override | ||
| 74 | + public void removeEventListener(OpenFlowEventListener listener) { | ||
| 75 | + // TODO Auto-generated method stub | ||
| 76 | + | ||
| 77 | + } | ||
| 66 | } | 78 | } | ... | ... |
| ... | @@ -3,8 +3,6 @@ package org.onlab.onos.openflow.controller.impl; | ... | @@ -3,8 +3,6 @@ package org.onlab.onos.openflow.controller.impl; |
| 3 | import static org.onlab.util.Tools.namedThreads; | 3 | import static org.onlab.util.Tools.namedThreads; |
| 4 | 4 | ||
| 5 | import java.util.HashSet; | 5 | import java.util.HashSet; |
| 6 | -import java.util.List; | ||
| 7 | -import java.util.Map; | ||
| 8 | import java.util.Set; | 6 | import java.util.Set; |
| 9 | import java.util.concurrent.ConcurrentHashMap; | 7 | import java.util.concurrent.ConcurrentHashMap; |
| 10 | import java.util.concurrent.ExecutorService; | 8 | import java.util.concurrent.ExecutorService; |
| ... | @@ -16,10 +14,10 @@ import org.apache.felix.scr.annotations.Activate; | ... | @@ -16,10 +14,10 @@ import org.apache.felix.scr.annotations.Activate; |
| 16 | import org.apache.felix.scr.annotations.Component; | 14 | import org.apache.felix.scr.annotations.Component; |
| 17 | import org.apache.felix.scr.annotations.Deactivate; | 15 | import org.apache.felix.scr.annotations.Deactivate; |
| 18 | import org.apache.felix.scr.annotations.Service; | 16 | import org.apache.felix.scr.annotations.Service; |
| 19 | -import org.onlab.onos.of.controller.OpenFlowEventListener; | ||
| 20 | import org.onlab.onos.openflow.controller.DefaultOpenFlowPacketContext; | 17 | import org.onlab.onos.openflow.controller.DefaultOpenFlowPacketContext; |
| 21 | import org.onlab.onos.openflow.controller.Dpid; | 18 | import org.onlab.onos.openflow.controller.Dpid; |
| 22 | import org.onlab.onos.openflow.controller.OpenFlowController; | 19 | import org.onlab.onos.openflow.controller.OpenFlowController; |
| 20 | +import org.onlab.onos.openflow.controller.OpenFlowEventListener; | ||
| 23 | import org.onlab.onos.openflow.controller.OpenFlowPacketContext; | 21 | import org.onlab.onos.openflow.controller.OpenFlowPacketContext; |
| 24 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; | 22 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
| 25 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; | 23 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; |
| ... | @@ -29,13 +27,12 @@ import org.onlab.onos.openflow.controller.driver.OpenFlowAgent; | ... | @@ -29,13 +27,12 @@ import org.onlab.onos.openflow.controller.driver.OpenFlowAgent; |
| 29 | import org.projectfloodlight.openflow.protocol.OFMessage; | 27 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 30 | import org.projectfloodlight.openflow.protocol.OFPacketIn; | 28 | import org.projectfloodlight.openflow.protocol.OFPacketIn; |
| 31 | import org.projectfloodlight.openflow.protocol.OFPortStatus; | 29 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 32 | -import org.projectfloodlight.openflow.protocol.OFType; | ||
| 33 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
| 34 | import org.slf4j.LoggerFactory; | 31 | import org.slf4j.LoggerFactory; |
| 35 | 32 | ||
| 36 | import com.google.common.collect.ArrayListMultimap; | 33 | import com.google.common.collect.ArrayListMultimap; |
| 37 | -import com.google.common.collect.Maps; | ||
| 38 | import com.google.common.collect.Multimap; | 34 | import com.google.common.collect.Multimap; |
| 35 | +import com.google.common.collect.Sets; | ||
| 39 | 36 | ||
| 40 | @Component(immediate = true) | 37 | @Component(immediate = true) |
| 41 | @Service | 38 | @Service |
| ... | @@ -45,7 +42,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -45,7 +42,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 45 | LoggerFactory.getLogger(OpenFlowControllerImpl.class); | 42 | LoggerFactory.getLogger(OpenFlowControllerImpl.class); |
| 46 | 43 | ||
| 47 | private final ExecutorService executor = Executors.newFixedThreadPool(16, | 44 | private final ExecutorService executor = Executors.newFixedThreadPool(16, |
| 48 | - namedThreads("of-event-dispatch-%d")); | 45 | + namedThreads("of-event-%d")); |
| 49 | 46 | ||
| 50 | 47 | ||
| 51 | protected ConcurrentHashMap<Dpid, OpenFlowSwitch> connectedSwitches = | 48 | protected ConcurrentHashMap<Dpid, OpenFlowSwitch> connectedSwitches = |
| ... | @@ -61,7 +58,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -61,7 +58,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 61 | protected Multimap<Integer, PacketListener> ofPacketListener = | 58 | protected Multimap<Integer, PacketListener> ofPacketListener = |
| 62 | ArrayListMultimap.create(); | 59 | ArrayListMultimap.create(); |
| 63 | 60 | ||
| 64 | - protected Map<OFType, List<OpenFlowEventListener>> ofEventListener = Maps.newHashMap(); | 61 | + protected Set<OpenFlowEventListener> ofEventListener = Sets.newHashSet(); |
| 65 | 62 | ||
| 66 | private final Controller ctrl = new Controller(); | 63 | private final Controller ctrl = new Controller(); |
| 67 | 64 | ||
| ... | @@ -128,6 +125,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -128,6 +125,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 128 | } | 125 | } |
| 129 | 126 | ||
| 130 | @Override | 127 | @Override |
| 128 | + public void addEventListener(OpenFlowEventListener listener) { | ||
| 129 | + ofEventListener.add(listener); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + @Override | ||
| 133 | + public void removeEventListener(OpenFlowEventListener listener) { | ||
| 134 | + ofEventListener.remove(listener); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 131 | public void write(Dpid dpid, OFMessage msg) { | 138 | public void write(Dpid dpid, OFMessage msg) { |
| 132 | this.getSwitch(dpid).sendMsg(msg); | 139 | this.getSwitch(dpid).sendMsg(msg); |
| 133 | } | 140 | } |
| ... | @@ -320,14 +327,11 @@ public class OpenFlowControllerImpl implements OpenFlowController { | ... | @@ -320,14 +327,11 @@ public class OpenFlowControllerImpl implements OpenFlowController { |
| 320 | 327 | ||
| 321 | @Override | 328 | @Override |
| 322 | public void run() { | 329 | public void run() { |
| 323 | - List<OpenFlowEventListener> listeners = | 330 | + for (OpenFlowEventListener listener : ofEventListener) { |
| 324 | - ofEventListener.get(OFType.FLOW_REMOVED); | ||
| 325 | - for (OpenFlowEventListener listener : listeners) { | ||
| 326 | listener.handleMessage(dpid, msg); | 331 | listener.handleMessage(dpid, msg); |
| 327 | } | 332 | } |
| 328 | } | 333 | } |
| 329 | 334 | ||
| 330 | } | 335 | } |
| 331 | 336 | ||
| 332 | - | ||
| 333 | } | 337 | } | ... | ... |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowModBuilder.java
0 → 100644
| 1 | +package org.onlab.onos.provider.of.flow.impl; | ||
| 2 | + | ||
| 3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 4 | + | ||
| 5 | +import java.util.Collections; | ||
| 6 | +import java.util.LinkedList; | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +import org.onlab.onos.net.flow.FlowRule; | ||
| 10 | +import org.onlab.onos.net.flow.TrafficSelector; | ||
| 11 | +import org.onlab.onos.net.flow.TrafficTreatment; | ||
| 12 | +import org.onlab.onos.net.flow.criteria.Criteria.EthCriterion; | ||
| 13 | +import org.onlab.onos.net.flow.criteria.Criteria.EthTypeCriterion; | ||
| 14 | +import org.onlab.onos.net.flow.criteria.Criteria.IPCriterion; | ||
| 15 | +import org.onlab.onos.net.flow.criteria.Criteria.IPProtocolCriterion; | ||
| 16 | +import org.onlab.onos.net.flow.criteria.Criteria.PortCriterion; | ||
| 17 | +import org.onlab.onos.net.flow.criteria.Criteria.VlanIdCriterion; | ||
| 18 | +import org.onlab.onos.net.flow.criteria.Criteria.VlanPcpCriterion; | ||
| 19 | +import org.onlab.onos.net.flow.criteria.Criterion; | ||
| 20 | +import org.onlab.onos.net.flow.instructions.Instruction; | ||
| 21 | +import org.onlab.onos.net.flow.instructions.Instructions.OutputInstruction; | ||
| 22 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction; | ||
| 23 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; | ||
| 24 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; | ||
| 25 | +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction; | ||
| 26 | +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction; | ||
| 27 | +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction; | ||
| 28 | +import org.projectfloodlight.openflow.protocol.OFFactory; | ||
| 29 | +import org.projectfloodlight.openflow.protocol.OFFlowMod; | ||
| 30 | +import org.projectfloodlight.openflow.protocol.OFFlowModFlags; | ||
| 31 | +import org.projectfloodlight.openflow.protocol.action.OFAction; | ||
| 32 | +import org.projectfloodlight.openflow.protocol.match.Match; | ||
| 33 | +import org.projectfloodlight.openflow.protocol.match.MatchField; | ||
| 34 | +import org.projectfloodlight.openflow.types.EthType; | ||
| 35 | +import org.projectfloodlight.openflow.types.IPv4Address; | ||
| 36 | +import org.projectfloodlight.openflow.types.IpProtocol; | ||
| 37 | +import org.projectfloodlight.openflow.types.MacAddress; | ||
| 38 | +import org.projectfloodlight.openflow.types.Masked; | ||
| 39 | +import org.projectfloodlight.openflow.types.OFBufferId; | ||
| 40 | +import org.projectfloodlight.openflow.types.OFPort; | ||
| 41 | +import org.projectfloodlight.openflow.types.OFVlanVidMatch; | ||
| 42 | +import org.projectfloodlight.openflow.types.VlanPcp; | ||
| 43 | +import org.projectfloodlight.openflow.types.VlanVid; | ||
| 44 | +import org.slf4j.Logger; | ||
| 45 | + | ||
| 46 | + | ||
| 47 | +public class FlowModBuilder { | ||
| 48 | + | ||
| 49 | + private final Logger log = getLogger(getClass()); | ||
| 50 | + | ||
| 51 | + private final OFFactory factory; | ||
| 52 | + private final TrafficTreatment treatment; | ||
| 53 | + private final TrafficSelector selector; | ||
| 54 | + | ||
| 55 | + private final int priority; | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + public FlowModBuilder(FlowRule flowRule, OFFactory factory) { | ||
| 60 | + this.factory = factory; | ||
| 61 | + this.treatment = flowRule.treatment(); | ||
| 62 | + this.selector = flowRule.selector(); | ||
| 63 | + this.priority = flowRule.priority(); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public OFFlowMod buildFlowMod() { | ||
| 67 | + Match match = buildMatch(); | ||
| 68 | + List<OFAction> actions = buildActions(); | ||
| 69 | + | ||
| 70 | + //TODO: what to do without bufferid? do we assume that there will be a pktout as well? | ||
| 71 | + OFFlowMod fm = factory.buildFlowModify() | ||
| 72 | + .setBufferId(OFBufferId.NO_BUFFER) | ||
| 73 | + .setActions(actions) | ||
| 74 | + .setMatch(match) | ||
| 75 | + .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) | ||
| 76 | + .setIdleTimeout(10) | ||
| 77 | + .setHardTimeout(10) | ||
| 78 | + .setPriority(priority) | ||
| 79 | + .build(); | ||
| 80 | + | ||
| 81 | + return fm; | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + private List<OFAction> buildActions() { | ||
| 86 | + List<OFAction> acts = new LinkedList<>(); | ||
| 87 | + for (Instruction i : treatment.instructions()) { | ||
| 88 | + switch (i.type()) { | ||
| 89 | + case DROP: | ||
| 90 | + log.warn("Saw drop action; assigning drop action"); | ||
| 91 | + return new LinkedList<>(); | ||
| 92 | + case L2MODIFICATION: | ||
| 93 | + acts.add(buildL2Modification(i)); | ||
| 94 | + case L3MODIFICATION: | ||
| 95 | + acts.add(buildL3Modification(i)); | ||
| 96 | + case OUTPUT: | ||
| 97 | + OutputInstruction out = (OutputInstruction) i; | ||
| 98 | + acts.add(factory.actions().buildOutput().setPort( | ||
| 99 | + OFPort.of((int) out.port().toLong())).build()); | ||
| 100 | + break; | ||
| 101 | + case GROUP: | ||
| 102 | + default: | ||
| 103 | + log.warn("Instruction type {} not yet implemented.", i.type()); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + return acts; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + private OFAction buildL3Modification(Instruction i) { | ||
| 111 | + L3ModificationInstruction l3m = (L3ModificationInstruction) i; | ||
| 112 | + ModIPInstruction ip; | ||
| 113 | + switch (l3m.subtype()) { | ||
| 114 | + case L3_DST: | ||
| 115 | + ip = (ModIPInstruction) i; | ||
| 116 | + return factory.actions().setNwDst(IPv4Address.of(ip.ip().toInt())); | ||
| 117 | + case L3_SRC: | ||
| 118 | + ip = (ModIPInstruction) i; | ||
| 119 | + return factory.actions().setNwSrc(IPv4Address.of(ip.ip().toInt())); | ||
| 120 | + default: | ||
| 121 | + log.warn("Unimplemented action type {}.", l3m.subtype()); | ||
| 122 | + break; | ||
| 123 | + } | ||
| 124 | + return null; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + private OFAction buildL2Modification(Instruction i) { | ||
| 128 | + L2ModificationInstruction l2m = (L2ModificationInstruction) i; | ||
| 129 | + ModEtherInstruction eth; | ||
| 130 | + switch (l2m.subtype()) { | ||
| 131 | + case L2_DST: | ||
| 132 | + eth = (ModEtherInstruction) l2m; | ||
| 133 | + return factory.actions().setDlDst(MacAddress.of(eth.mac().toLong())); | ||
| 134 | + case L2_SRC: | ||
| 135 | + eth = (ModEtherInstruction) l2m; | ||
| 136 | + return factory.actions().setDlSrc(MacAddress.of(eth.mac().toLong())); | ||
| 137 | + case VLAN_ID: | ||
| 138 | + ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; | ||
| 139 | + return factory.actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId.toShort())); | ||
| 140 | + case VLAN_PCP: | ||
| 141 | + ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; | ||
| 142 | + return factory.actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); | ||
| 143 | + default: | ||
| 144 | + log.warn("Unimplemented action type {}.", l2m.subtype()); | ||
| 145 | + break; | ||
| 146 | + } | ||
| 147 | + return null; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + private Match buildMatch() { | ||
| 151 | + Match.Builder mBuilder = factory.buildMatch(); | ||
| 152 | + EthCriterion eth; | ||
| 153 | + IPCriterion ip; | ||
| 154 | + for (Criterion c : selector.criteria()) { | ||
| 155 | + switch (c.type()) { | ||
| 156 | + case IN_PORT: | ||
| 157 | + PortCriterion inport = (PortCriterion) c; | ||
| 158 | + mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inport.port().toLong())); | ||
| 159 | + break; | ||
| 160 | + case ETH_SRC: | ||
| 161 | + eth = (EthCriterion) c; | ||
| 162 | + mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(eth.mac().toLong())); | ||
| 163 | + break; | ||
| 164 | + case ETH_DST: | ||
| 165 | + eth = (EthCriterion) c; | ||
| 166 | + mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(eth.mac().toLong())); | ||
| 167 | + break; | ||
| 168 | + case ETH_TYPE: | ||
| 169 | + EthTypeCriterion ethType = (EthTypeCriterion) c; | ||
| 170 | + mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType())); | ||
| 171 | + break; | ||
| 172 | + case IPV4_DST: | ||
| 173 | + ip = (IPCriterion) c; | ||
| 174 | + if (ip.ip().isMasked()) { | ||
| 175 | + Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip.ip().toInt()), | ||
| 176 | + IPv4Address.of(ip.ip().netmask().toInt())); | ||
| 177 | + mBuilder.setMasked(MatchField.IPV4_DST, maskedIp); | ||
| 178 | + } else { | ||
| 179 | + mBuilder.setExact(MatchField.IPV4_DST, IPv4Address.of(ip.ip().toInt())); | ||
| 180 | + } | ||
| 181 | + break; | ||
| 182 | + case IPV4_SRC: | ||
| 183 | + ip = (IPCriterion) c; | ||
| 184 | + if (ip.ip().isMasked()) { | ||
| 185 | + Masked<IPv4Address> maskedIp = Masked.of(IPv4Address.of(ip.ip().toInt()), | ||
| 186 | + IPv4Address.of(ip.ip().netmask().toInt())); | ||
| 187 | + mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp); | ||
| 188 | + } else { | ||
| 189 | + mBuilder.setExact(MatchField.IPV4_SRC, IPv4Address.of(ip.ip().toInt())); | ||
| 190 | + } | ||
| 191 | + break; | ||
| 192 | + case IP_PROTO: | ||
| 193 | + IPProtocolCriterion p = (IPProtocolCriterion) c; | ||
| 194 | + mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); | ||
| 195 | + break; | ||
| 196 | + case VLAN_PCP: | ||
| 197 | + VlanPcpCriterion vpcp = (VlanPcpCriterion) c; | ||
| 198 | + mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); | ||
| 199 | + break; | ||
| 200 | + case VLAN_VID: | ||
| 201 | + VlanIdCriterion vid = (VlanIdCriterion) c; | ||
| 202 | + mBuilder.setExact(MatchField.VLAN_VID, | ||
| 203 | + OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort()))); | ||
| 204 | + break; | ||
| 205 | + case ARP_OP: | ||
| 206 | + case ARP_SHA: | ||
| 207 | + case ARP_SPA: | ||
| 208 | + case ARP_THA: | ||
| 209 | + case ARP_TPA: | ||
| 210 | + case ICMPV4_CODE: | ||
| 211 | + case ICMPV4_TYPE: | ||
| 212 | + case ICMPV6_CODE: | ||
| 213 | + case ICMPV6_TYPE: | ||
| 214 | + case IN_PHY_PORT: | ||
| 215 | + case IPV6_DST: | ||
| 216 | + case IPV6_EXTHDR: | ||
| 217 | + case IPV6_FLABEL: | ||
| 218 | + case IPV6_ND_SLL: | ||
| 219 | + case IPV6_ND_TARGET: | ||
| 220 | + case IPV6_ND_TLL: | ||
| 221 | + case IPV6_SRC: | ||
| 222 | + case IP_DSCP: | ||
| 223 | + case IP_ECN: | ||
| 224 | + case METADATA: | ||
| 225 | + case MPLS_BOS: | ||
| 226 | + case MPLS_LABEL: | ||
| 227 | + case MPLS_TC: | ||
| 228 | + case PBB_ISID: | ||
| 229 | + case SCTP_DST: | ||
| 230 | + case SCTP_SRC: | ||
| 231 | + case TCP_DST: | ||
| 232 | + case TCP_SRC: | ||
| 233 | + case TUNNEL_ID: | ||
| 234 | + case UDP_DST: | ||
| 235 | + case UDP_SRC: | ||
| 236 | + default: | ||
| 237 | + log.warn("Match type {} not yet implemented.", c.type()); | ||
| 238 | + } | ||
| 239 | + } | ||
| 240 | + return mBuilder.build(); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | +} |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/FlowStatsCollector.java
0 → 100644
| 1 | +package org.onlab.onos.provider.of.flow.impl; | ||
| 2 | + | ||
| 3 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 4 | + | ||
| 5 | +import java.util.concurrent.TimeUnit; | ||
| 6 | + | ||
| 7 | +import org.jboss.netty.util.HashedWheelTimer; | ||
| 8 | +import org.jboss.netty.util.Timeout; | ||
| 9 | +import org.jboss.netty.util.TimerTask; | ||
| 10 | +import org.onlab.onos.openflow.controller.OpenFlowSwitch; | ||
| 11 | +import org.onlab.util.Timer; | ||
| 12 | +import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest; | ||
| 13 | +import org.projectfloodlight.openflow.types.OFPort; | ||
| 14 | +import org.projectfloodlight.openflow.types.TableId; | ||
| 15 | +import org.slf4j.Logger; | ||
| 16 | + | ||
| 17 | +public class FlowStatsCollector implements TimerTask { | ||
| 18 | + | ||
| 19 | + private final Logger log = getLogger(getClass()); | ||
| 20 | + | ||
| 21 | + private final HashedWheelTimer timer = Timer.getTimer(); | ||
| 22 | + private final OpenFlowSwitch sw; | ||
| 23 | + private final int refreshInterval; | ||
| 24 | + | ||
| 25 | + private Timeout timeout; | ||
| 26 | + | ||
| 27 | + private boolean stopTimer = false;; | ||
| 28 | + | ||
| 29 | + public FlowStatsCollector(OpenFlowSwitch sw, int refreshInterval) { | ||
| 30 | + this.sw = sw; | ||
| 31 | + this.refreshInterval = refreshInterval; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + public void run(Timeout timeout) throws Exception { | ||
| 36 | + log.debug("Collecting stats for {}", this.sw.getStringId()); | ||
| 37 | + | ||
| 38 | + sendFlowStatistics(); | ||
| 39 | + | ||
| 40 | + if (!this.stopTimer) { | ||
| 41 | + log.debug("Scheduling stats collection in {} seconds for {}", | ||
| 42 | + this.refreshInterval, this.sw.getStringId()); | ||
| 43 | + timeout.getTimer().newTimeout(this, refreshInterval, | ||
| 44 | + TimeUnit.SECONDS); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + private void sendFlowStatistics() { | ||
| 51 | + OFFlowStatsRequest request = sw.factory().buildFlowStatsRequest() | ||
| 52 | + .setMatch(sw.factory().matchWildcardAll()) | ||
| 53 | + .setTableId(TableId.ALL) | ||
| 54 | + .setOutPort(OFPort.NO_MASK) | ||
| 55 | + .build(); | ||
| 56 | + | ||
| 57 | + this.sw.sendMsg(request); | ||
| 58 | + | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void start() { | ||
| 62 | + | ||
| 63 | + /* | ||
| 64 | + * Initially start polling quickly. Then drop down to configured value | ||
| 65 | + */ | ||
| 66 | + log.info("Starting Stats collection thread for {}", | ||
| 67 | + this.sw.getStringId()); | ||
| 68 | + timeout = timer.newTimeout(this, 1, TimeUnit.SECONDS); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public void stop() { | ||
| 72 | + log.info("Stopping Stats collection thread for {}", | ||
| 73 | + this.sw.getStringId()); | ||
| 74 | + this.stopTimer = true; | ||
| 75 | + timeout.cancel(); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | +} |
providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
| ... | @@ -2,6 +2,8 @@ package org.onlab.onos.provider.of.flow.impl; | ... | @@ -2,6 +2,8 @@ package org.onlab.onos.provider.of.flow.impl; |
| 2 | 2 | ||
| 3 | import static org.slf4j.LoggerFactory.getLogger; | 3 | import static org.slf4j.LoggerFactory.getLogger; |
| 4 | 4 | ||
| 5 | +import java.util.Map; | ||
| 6 | + | ||
| 5 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
| 6 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
| 7 | import org.apache.felix.scr.annotations.Deactivate; | 9 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -17,9 +19,9 @@ import org.onlab.onos.net.flow.FlowRuleProviderService; | ... | @@ -17,9 +19,9 @@ import org.onlab.onos.net.flow.FlowRuleProviderService; |
| 17 | import org.onlab.onos.net.provider.AbstractProvider; | 19 | import org.onlab.onos.net.provider.AbstractProvider; |
| 18 | import org.onlab.onos.net.provider.ProviderId; | 20 | import org.onlab.onos.net.provider.ProviderId; |
| 19 | import org.onlab.onos.net.topology.TopologyService; | 21 | import org.onlab.onos.net.topology.TopologyService; |
| 20 | -import org.onlab.onos.of.controller.OpenFlowEventListener; | ||
| 21 | import org.onlab.onos.openflow.controller.Dpid; | 22 | import org.onlab.onos.openflow.controller.Dpid; |
| 22 | import org.onlab.onos.openflow.controller.OpenFlowController; | 23 | import org.onlab.onos.openflow.controller.OpenFlowController; |
| 24 | +import org.onlab.onos.openflow.controller.OpenFlowEventListener; | ||
| 23 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; | 25 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
| 24 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; | 26 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; |
| 25 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; | 27 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
| ... | @@ -27,6 +29,8 @@ import org.projectfloodlight.openflow.protocol.OFMessage; | ... | @@ -27,6 +29,8 @@ import org.projectfloodlight.openflow.protocol.OFMessage; |
| 27 | import org.projectfloodlight.openflow.protocol.OFPortStatus; | 29 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
| 28 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
| 29 | 31 | ||
| 32 | +import com.google.common.collect.Maps; | ||
| 33 | + | ||
| 30 | /** | 34 | /** |
| 31 | * Provider which uses an OpenFlow controller to detect network | 35 | * Provider which uses an OpenFlow controller to detect network |
| 32 | * end-station hosts. | 36 | * end-station hosts. |
| ... | @@ -47,6 +51,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -47,6 +51,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 47 | 51 | ||
| 48 | private FlowRuleProviderService providerService; | 52 | private FlowRuleProviderService providerService; |
| 49 | 53 | ||
| 54 | + private final InternalFlowProvider listener = new InternalFlowProvider(); | ||
| 55 | + | ||
| 50 | /** | 56 | /** |
| 51 | * Creates an OpenFlow host provider. | 57 | * Creates an OpenFlow host provider. |
| 52 | */ | 58 | */ |
| ... | @@ -57,6 +63,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -57,6 +63,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 57 | @Activate | 63 | @Activate |
| 58 | public void activate() { | 64 | public void activate() { |
| 59 | providerService = providerRegistry.register(this); | 65 | providerService = providerRegistry.register(this); |
| 66 | + controller.addListener(listener); | ||
| 67 | + controller.addEventListener(listener); | ||
| 60 | log.info("Started"); | 68 | log.info("Started"); |
| 61 | } | 69 | } |
| 62 | 70 | ||
| ... | @@ -99,16 +107,18 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -99,16 +107,18 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 99 | private class InternalFlowProvider | 107 | private class InternalFlowProvider |
| 100 | implements OpenFlowSwitchListener, OpenFlowEventListener { | 108 | implements OpenFlowSwitchListener, OpenFlowEventListener { |
| 101 | 109 | ||
| 110 | + private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap(); | ||
| 102 | 111 | ||
| 103 | @Override | 112 | @Override |
| 104 | public void switchAdded(Dpid dpid) { | 113 | public void switchAdded(Dpid dpid) { |
| 105 | - | 114 | + FlowStatsCollector fsc = new FlowStatsCollector(controller.getSwitch(dpid), 1); |
| 106 | - | 115 | + fsc.start(); |
| 116 | + collectors.put(dpid, fsc); | ||
| 107 | } | 117 | } |
| 108 | 118 | ||
| 109 | @Override | 119 | @Override |
| 110 | public void switchRemoved(Dpid dpid) { | 120 | public void switchRemoved(Dpid dpid) { |
| 111 | - | 121 | + collectors.remove(dpid).stop(); |
| 112 | 122 | ||
| 113 | } | 123 | } |
| 114 | 124 | ||
| ... | @@ -121,11 +131,13 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -121,11 +131,13 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
| 121 | public void handleMessage(Dpid dpid, OFMessage msg) { | 131 | public void handleMessage(Dpid dpid, OFMessage msg) { |
| 122 | switch (msg.getType()) { | 132 | switch (msg.getType()) { |
| 123 | case FLOW_REMOVED: | 133 | case FLOW_REMOVED: |
| 134 | + //TODO: make this better | ||
| 124 | OFFlowRemoved removed = (OFFlowRemoved) msg; | 135 | OFFlowRemoved removed = (OFFlowRemoved) msg; |
| 125 | FlowRule fr = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), null, null); | 136 | FlowRule fr = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), null, null); |
| 126 | providerService.flowRemoved(fr); | 137 | providerService.flowRemoved(fr); |
| 127 | break; | 138 | break; |
| 128 | case STATS_REPLY: | 139 | case STATS_REPLY: |
| 140 | + break; | ||
| 129 | case BARRIER_REPLY: | 141 | case BARRIER_REPLY: |
| 130 | case ERROR: | 142 | case ERROR: |
| 131 | default: | 143 | default: | ... | ... |
-
Please register or login to post a comment