alshabib

stats reported

...@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow; ...@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow;
2 2
3 import static com.google.common.base.MoreObjects.toStringHelper; 3 import static com.google.common.base.MoreObjects.toStringHelper;
4 4
5 +import java.util.Objects;
6 +
5 import org.onlab.onos.net.DeviceId; 7 import org.onlab.onos.net.DeviceId;
6 8
7 public class DefaultFlowRule implements FlowRule { 9 public class DefaultFlowRule implements FlowRule {
...@@ -12,10 +14,10 @@ public class DefaultFlowRule implements FlowRule { ...@@ -12,10 +14,10 @@ public class DefaultFlowRule implements FlowRule {
12 private final TrafficTreatment treatment; 14 private final TrafficTreatment treatment;
13 private final FlowId id; 15 private final FlowId id;
14 private final long created; 16 private final long created;
15 - private long life; 17 + private final long life;
16 - private long idle; 18 + private final long idle;
17 - private long packets; 19 + private final long packets;
18 - private long bytes; 20 + private final long bytes;
19 21
20 22
21 public DefaultFlowRule(DeviceId deviceId, 23 public DefaultFlowRule(DeviceId deviceId,
...@@ -32,15 +34,21 @@ public class DefaultFlowRule implements FlowRule { ...@@ -32,15 +34,21 @@ public class DefaultFlowRule implements FlowRule {
32 this.created = System.currentTimeMillis(); 34 this.created = System.currentTimeMillis();
33 } 35 }
34 36
35 - // TODO: Decide whether to take the flowId from the underlying flowentry.
36 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 37 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
37 TrafficTreatment treatment, int priority, 38 TrafficTreatment treatment, int priority,
38 - long life, long idle, long packets, long bytes) { 39 + long life, long idle, long packets, long bytes, Integer flowId) {
39 - this(deviceId, selector, treatment, priority); 40 + this.deviceId = deviceId;
41 + this.priority = priority;
42 + this.selector = selector;
43 + this.treatment = treatment;
44 +
45 + this.id = FlowId.valueOf(flowId);
46 +
40 this.life = life; 47 this.life = life;
41 this.idle = idle; 48 this.idle = idle;
42 this.packets = packets; 49 this.packets = packets;
43 this.bytes = bytes; 50 this.bytes = bytes;
51 + this.created = System.currentTimeMillis();
44 } 52 }
45 53
46 54
...@@ -97,11 +105,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -97,11 +105,7 @@ public class DefaultFlowRule implements FlowRule {
97 * @see java.lang.Object#equals(java.lang.Object) 105 * @see java.lang.Object#equals(java.lang.Object)
98 */ 106 */
99 public int hashCode() { 107 public int hashCode() {
100 - final int prime = 31; 108 + return Objects.hash(deviceId, selector, treatment);
101 - int result = prime * this.deviceId().hashCode();
102 - result = prime * result + selector.hashCode();
103 - result = prime * result + treatment.hashCode();
104 - return result;
105 } 109 }
106 110
107 @Override 111 @Override
...@@ -140,4 +144,5 @@ public class DefaultFlowRule implements FlowRule { ...@@ -140,4 +144,5 @@ public class DefaultFlowRule implements FlowRule {
140 .toString(); 144 .toString();
141 } 145 }
142 146
147 +
143 } 148 }
......
...@@ -6,6 +6,7 @@ import java.util.Collections; ...@@ -6,6 +6,7 @@ import java.util.Collections;
6 import java.util.LinkedList; 6 import java.util.LinkedList;
7 import java.util.List; 7 import java.util.List;
8 8
9 +import org.onlab.onos.net.flow.FlowId;
9 import org.onlab.onos.net.flow.FlowRule; 10 import org.onlab.onos.net.flow.FlowRule;
10 import org.onlab.onos.net.flow.TrafficSelector; 11 import org.onlab.onos.net.flow.TrafficSelector;
11 import org.onlab.onos.net.flow.TrafficTreatment; 12 import org.onlab.onos.net.flow.TrafficTreatment;
...@@ -39,6 +40,7 @@ import org.projectfloodlight.openflow.types.Masked; ...@@ -39,6 +40,7 @@ import org.projectfloodlight.openflow.types.Masked;
39 import org.projectfloodlight.openflow.types.OFBufferId; 40 import org.projectfloodlight.openflow.types.OFBufferId;
40 import org.projectfloodlight.openflow.types.OFPort; 41 import org.projectfloodlight.openflow.types.OFPort;
41 import org.projectfloodlight.openflow.types.OFVlanVidMatch; 42 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
43 +import org.projectfloodlight.openflow.types.U64;
42 import org.projectfloodlight.openflow.types.VlanPcp; 44 import org.projectfloodlight.openflow.types.VlanPcp;
43 import org.projectfloodlight.openflow.types.VlanVid; 45 import org.projectfloodlight.openflow.types.VlanVid;
44 import org.slf4j.Logger; 46 import org.slf4j.Logger;
...@@ -54,6 +56,8 @@ public class FlowModBuilder { ...@@ -54,6 +56,8 @@ public class FlowModBuilder {
54 56
55 private final int priority; 57 private final int priority;
56 58
59 + private final FlowId cookie;
60 +
57 61
58 62
59 public FlowModBuilder(FlowRule flowRule, OFFactory factory) { 63 public FlowModBuilder(FlowRule flowRule, OFFactory factory) {
...@@ -61,6 +65,7 @@ public class FlowModBuilder { ...@@ -61,6 +65,7 @@ public class FlowModBuilder {
61 this.treatment = flowRule.treatment(); 65 this.treatment = flowRule.treatment();
62 this.selector = flowRule.selector(); 66 this.selector = flowRule.selector();
63 this.priority = flowRule.priority(); 67 this.priority = flowRule.priority();
68 + this.cookie = flowRule.id();
64 } 69 }
65 70
66 public OFFlowMod buildFlowMod() { 71 public OFFlowMod buildFlowMod() {
...@@ -69,6 +74,7 @@ public class FlowModBuilder { ...@@ -69,6 +74,7 @@ public class FlowModBuilder {
69 74
70 //TODO: what to do without bufferid? do we assume that there will be a pktout as well? 75 //TODO: what to do without bufferid? do we assume that there will be a pktout as well?
71 OFFlowMod fm = factory.buildFlowModify() 76 OFFlowMod fm = factory.buildFlowModify()
77 + .setCookie(U64.of(cookie.value()))
72 .setBufferId(OFBufferId.NO_BUFFER) 78 .setBufferId(OFBufferId.NO_BUFFER)
73 .setActions(actions) 79 .setActions(actions)
74 .setMatch(match) 80 .setMatch(match)
......
1 +package org.onlab.onos.provider.of.flow.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import java.util.List;
6 +
7 +import org.onlab.onos.net.DeviceId;
8 +import org.onlab.onos.net.PortNumber;
9 +import org.onlab.onos.net.flow.DefaultFlowRule;
10 +import org.onlab.onos.net.flow.DefaultTrafficSelector;
11 +import org.onlab.onos.net.flow.DefaultTrafficTreatment;
12 +import org.onlab.onos.net.flow.FlowRule;
13 +import org.onlab.onos.net.flow.TrafficSelector;
14 +import org.onlab.onos.net.flow.TrafficTreatment;
15 +import org.onlab.onos.net.flow.criteria.Criteria;
16 +import org.onlab.onos.net.flow.instructions.Instructions;
17 +import org.onlab.onos.openflow.controller.Dpid;
18 +import org.onlab.packet.IpAddress;
19 +import org.onlab.packet.MacAddress;
20 +import org.onlab.packet.VlanId;
21 +import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
22 +import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
23 +import org.projectfloodlight.openflow.protocol.action.OFAction;
24 +import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
25 +import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
26 +import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
27 +import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
28 +import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
29 +import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
30 +import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
31 +import org.projectfloodlight.openflow.protocol.match.Match;
32 +import org.projectfloodlight.openflow.protocol.match.MatchField;
33 +import org.projectfloodlight.openflow.types.IPv4Address;
34 +import org.slf4j.Logger;
35 +
36 +public class FlowRuleBuilder {
37 + private final Logger log = getLogger(getClass());
38 +
39 + private final OFFlowStatsEntry stat;
40 + private final OFFlowRemoved removed;
41 +
42 + private final Match match;
43 + private final List<OFAction> actions;
44 +
45 + private final Dpid dpid;
46 +
47 +
48 +
49 +
50 + public FlowRuleBuilder(Dpid dpid, OFFlowStatsEntry entry) {
51 + this.stat = entry;
52 + this.match = entry.getMatch();
53 + this.actions = entry.getActions();
54 + this.dpid = dpid;
55 + removed = null;
56 + }
57 +
58 + public FlowRuleBuilder(Dpid dpid, OFFlowRemoved removed) {
59 + this.match = removed.getMatch();
60 + this.removed = removed;
61 +
62 + this.dpid = dpid;
63 + this.actions = null;
64 + this.stat = null;
65 +
66 + }
67 +
68 + public FlowRule build() {
69 + if (stat != null) {
70 + return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
71 + buildSelector(), buildTreatment(), stat.getPriority(),
72 + stat.getDurationNsec() / 1000000, stat.getIdleTimeout(),
73 + stat.getPacketCount().getValue(), stat.getByteCount().getValue(),
74 + (int) (stat.getCookie().getValue() & 0xFFFFFFFF));
75 + } else {
76 + // TODO: revisit potentially.
77 + return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
78 + buildSelector(), null, removed.getPriority(),
79 + removed.getDurationNsec() / 1000000, removed.getIdleTimeout(),
80 + removed.getPacketCount().getValue(), removed.getByteCount().getValue(),
81 + (int) (removed.getCookie().getValue() & 0xFFFFFFFF));
82 + }
83 + }
84 +
85 +
86 + private TrafficTreatment buildTreatment() {
87 + TrafficTreatment.Builder builder = new DefaultTrafficTreatment.Builder();
88 + // If this is a drop rule
89 + if (actions.size() == 0) {
90 + builder.add(Instructions.createDrop());
91 + return builder.build();
92 + }
93 + for (OFAction act : actions) {
94 + switch (act.getType()) {
95 + case OUTPUT:
96 + OFActionOutput out = (OFActionOutput) act;
97 + builder.add(Instructions.createOutput(
98 + PortNumber.portNumber(out.getPort().getPortNumber())));
99 + break;
100 + case SET_VLAN_PCP:
101 + OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
102 + builder.add(Instructions.modVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan())));
103 + break;
104 + case SET_VLAN_VID:
105 + OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
106 + builder.add(Instructions.modVlanId(VlanId.vlanId(pcp.getVlanPcp().getValue())));
107 + break;
108 + case SET_DL_DST:
109 + OFActionSetDlDst dldst = (OFActionSetDlDst) act;
110 + builder.add(Instructions.modL2Dst(
111 + MacAddress.valueOf(dldst.getDlAddr().getLong())));
112 + break;
113 + case SET_DL_SRC:
114 + OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
115 + builder.add(Instructions.modL2Src(
116 + MacAddress.valueOf(dlsrc.getDlAddr().getLong())));
117 +
118 + break;
119 + case SET_NW_DST:
120 + OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
121 + IPv4Address di = nwdst.getNwAddr();
122 + if (di.isCidrMask()) {
123 + builder.add(Instructions.modL3Dst(IpAddress.valueOf(di.getInt(),
124 + di.asCidrMaskLength())));
125 + } else {
126 + builder.add(Instructions.modL3Dst(IpAddress.valueOf(di.getInt())));
127 + }
128 + break;
129 + case SET_NW_SRC:
130 + OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
131 + IPv4Address si = nwsrc.getNwAddr();
132 + if (si.isCidrMask()) {
133 + builder.add(Instructions.modL3Dst(IpAddress.valueOf(si.getInt(),
134 + si.asCidrMaskLength())));
135 + } else {
136 + builder.add(Instructions.modL3Dst(IpAddress.valueOf(si.getInt())));
137 + }
138 + break;
139 + case SET_TP_DST:
140 + case SET_TP_SRC:
141 + case POP_MPLS:
142 + case POP_PBB:
143 + case POP_VLAN:
144 + case PUSH_MPLS:
145 + case PUSH_PBB:
146 + case PUSH_VLAN:
147 + case SET_FIELD:
148 + case SET_MPLS_LABEL:
149 + case SET_MPLS_TC:
150 + case SET_MPLS_TTL:
151 + case SET_NW_ECN:
152 + case SET_NW_TOS:
153 + case SET_NW_TTL:
154 + case SET_QUEUE:
155 + case STRIP_VLAN:
156 + case COPY_TTL_IN:
157 + case COPY_TTL_OUT:
158 + case DEC_MPLS_TTL:
159 + case DEC_NW_TTL:
160 + case ENQUEUE:
161 + case EXPERIMENTER:
162 + case GROUP:
163 + default:
164 + log.warn("Action type {} not yet implemented.", act.getType());
165 + }
166 + }
167 +
168 + return builder.build();
169 + }
170 +
171 + private TrafficSelector buildSelector() {
172 + TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
173 + for (MatchField<?> field : match.getMatchFields()) {
174 + switch (field.id) {
175 + case IN_PORT:
176 + builder.add(Criteria.matchInPort(PortNumber
177 + .portNumber(match.get(MatchField.IN_PORT).getPortNumber())));
178 + break;
179 + case ETH_SRC:
180 + MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
181 + builder.add(Criteria.matchEthSrc(sMac));
182 + break;
183 + case ETH_DST:
184 + MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
185 + builder.add(Criteria.matchEthSrc(dMac));
186 + break;
187 + case ETH_TYPE:
188 + int ethType = match.get(MatchField.ETH_TYPE).getValue();
189 + builder.add(Criteria.matchEthType((short) ethType));
190 + break;
191 + case IPV4_DST:
192 + IPv4Address di = match.get(MatchField.IPV4_DST);
193 + IpAddress dip;
194 + if (di.isCidrMask()) {
195 + dip = IpAddress.valueOf(di.getInt(), di.asCidrMaskLength());
196 + } else {
197 + dip = IpAddress.valueOf(di.getInt());
198 + }
199 + builder.add(Criteria.matchIPDst(dip));
200 + break;
201 + case IPV4_SRC:
202 + IPv4Address si = match.get(MatchField.IPV4_SRC);
203 + IpAddress sip;
204 + if (si.isCidrMask()) {
205 + sip = IpAddress.valueOf(si.getInt(), si.asCidrMaskLength());
206 + } else {
207 + sip = IpAddress.valueOf(si.getInt());
208 + }
209 + builder.add(Criteria.matchIPSrc(sip));
210 + break;
211 + case IP_PROTO:
212 + short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
213 + builder.add(Criteria.matchIPProtocol((byte) proto));
214 + break;
215 + case VLAN_PCP:
216 + byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
217 + builder.add(Criteria.matchVlanPcp(vlanPcp));
218 + break;
219 + case VLAN_VID:
220 + VlanId vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
221 + builder.add(Criteria.matchVlanId(vlanId));
222 + break;
223 + case ARP_OP:
224 + case ARP_SHA:
225 + case ARP_SPA:
226 + case ARP_THA:
227 + case ARP_TPA:
228 + case ICMPV4_CODE:
229 + case ICMPV4_TYPE:
230 + case ICMPV6_CODE:
231 + case ICMPV6_TYPE:
232 + case IN_PHY_PORT:
233 + case IPV6_DST:
234 + case IPV6_FLABEL:
235 + case IPV6_ND_SLL:
236 + case IPV6_ND_TARGET:
237 + case IPV6_ND_TLL:
238 + case IPV6_SRC:
239 + case IP_DSCP:
240 + case IP_ECN:
241 + case METADATA:
242 + case MPLS_LABEL:
243 + case MPLS_TC:
244 + case SCTP_DST:
245 + case SCTP_SRC:
246 + case TCP_DST:
247 + case TCP_SRC:
248 + case TUNNEL_ID:
249 + case UDP_DST:
250 + case UDP_SRC:
251 + default:
252 + log.warn("Match type {} not yet implemented.", field.id);
253 +
254 +
255 + }
256 + }
257 + return builder.build();
258 + }
259 +
260 +}
...@@ -10,8 +10,6 @@ import org.apache.felix.scr.annotations.Component; ...@@ -10,8 +10,6 @@ import org.apache.felix.scr.annotations.Component;
10 import org.apache.felix.scr.annotations.Deactivate; 10 import org.apache.felix.scr.annotations.Deactivate;
11 import org.apache.felix.scr.annotations.Reference; 11 import org.apache.felix.scr.annotations.Reference;
12 import org.apache.felix.scr.annotations.ReferenceCardinality; 12 import org.apache.felix.scr.annotations.ReferenceCardinality;
13 -import org.onlab.onos.net.DeviceId;
14 -import org.onlab.onos.net.flow.DefaultFlowRule;
15 import org.onlab.onos.net.flow.FlowRule; 13 import org.onlab.onos.net.flow.FlowRule;
16 import org.onlab.onos.net.flow.FlowRuleProvider; 14 import org.onlab.onos.net.flow.FlowRuleProvider;
17 import org.onlab.onos.net.flow.FlowRuleProviderRegistry; 15 import org.onlab.onos.net.flow.FlowRuleProviderRegistry;
...@@ -131,7 +129,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -131,7 +129,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
131 case FLOW_REMOVED: 129 case FLOW_REMOVED:
132 //TODO: make this better 130 //TODO: make this better
133 OFFlowRemoved removed = (OFFlowRemoved) msg; 131 OFFlowRemoved removed = (OFFlowRemoved) msg;
134 - FlowRule fr = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), null, null, 0); 132 +
133 + FlowRule fr = new FlowRuleBuilder(dpid, removed).build();
135 providerService.flowRemoved(fr); 134 providerService.flowRemoved(fr);
136 break; 135 break;
137 case STATS_REPLY: 136 case STATS_REPLY:
...@@ -154,6 +153,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -154,6 +153,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
154 for (OFFlowStatsEntry reply : replies.getEntries()) { 153 for (OFFlowStatsEntry reply : replies.getEntries()) {
155 entries.add(new FlowRuleBuilder(dpid, reply).build()); 154 entries.add(new FlowRuleBuilder(dpid, reply).build());
156 } 155 }
156 + log.debug("sending flowstats to core {}", entries);
157 providerService.pushFlowMetrics(entries); 157 providerService.pushFlowMetrics(entries);
158 } 158 }
159 159
......
...@@ -175,8 +175,10 @@ ...@@ -175,8 +175,10 @@
175 <property name="max" value="200"/> 175 <property name="max" value="200"/>
176 </module> 176 </module>
177 177
178 - <module name="ParameterNumber"/> 178 + <module name="ParameterNumber">
179 - 179 + <property name="max" value="10"/>
180 + <property name="tokens" value="CTOR_DEF"/>
181 + </module>
180 <!-- Checks for whitespace --> 182 <!-- Checks for whitespace -->
181 <!-- See http://checkstyle.sf.net/config_whitespace.html --> 183 <!-- See http://checkstyle.sf.net/config_whitespace.html -->
182 <module name="EmptyForIteratorPad"/> 184 <module name="EmptyForIteratorPad"/>
...@@ -272,6 +274,7 @@ ...@@ -272,6 +274,7 @@
272 <!-- <module name="TodoComment"/> --> 274 <!-- <module name="TodoComment"/> -->
273 <module name="UpperEll"/> 275 <module name="UpperEll"/>
274 276
277 +
275 </module> 278 </module>
276 279
277 </module> 280 </module>
......