tom

Merge remote-tracking branch 'origin/master'

...@@ -100,6 +100,7 @@ public class ReactiveForwarding { ...@@ -100,6 +100,7 @@ public class ReactiveForwarding {
100 context.block(); 100 context.block();
101 return; 101 return;
102 } 102 }
103 +
103 HostId id = HostId.hostId(ethPkt.getDestinationMAC()); 104 HostId id = HostId.hostId(ethPkt.getDestinationMAC());
104 105
105 // Do we know who this is for? If not, flood and bail. 106 // Do we know who this is for? If not, flood and bail.
...@@ -112,7 +113,9 @@ public class ReactiveForwarding { ...@@ -112,7 +113,9 @@ public class ReactiveForwarding {
112 // Are we on an edge switch that our destination is on? If so, 113 // Are we on an edge switch that our destination is on? If so,
113 // simply forward out to the destination and bail. 114 // simply forward out to the destination and bail.
114 if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) { 115 if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) {
115 - installRule(context, dst.location().port()); 116 + if (!context.inPacket().receivedFrom().port().equals(dst.location().port())) {
117 + installRule(context, dst.location().port());
118 + }
116 return; 119 return;
117 } 120 }
118 121
...@@ -175,21 +178,24 @@ public class ReactiveForwarding { ...@@ -175,21 +178,24 @@ public class ReactiveForwarding {
175 // We don't yet support bufferids in the flowservice so packet out first. 178 // We don't yet support bufferids in the flowservice so packet out first.
176 packetOut(context, portNumber); 179 packetOut(context, portNumber);
177 180
178 - // Install the flow rule to handle this type of message from now on. 181 + if (context.inPacket().parsed().getEtherType() == Ethernet.TYPE_IPV4) {
179 - Ethernet inPkt = context.inPacket().parsed();
180 - TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
181 - builder.matchEthType(inPkt.getEtherType())
182 - .matchEthSrc(inPkt.getSourceMAC())
183 - .matchEthDst(inPkt.getDestinationMAC())
184 - .matchInport(context.inPacket().receivedFrom().port());
185 182
186 - TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder(); 183 + // Install the flow rule to handle this type of message from now on.
187 - treat.setOutput(portNumber); 184 + Ethernet inPkt = context.inPacket().parsed();
185 + TrafficSelector.Builder builder = new DefaultTrafficSelector.Builder();
186 + builder.matchEthType(inPkt.getEtherType())
187 + .matchEthSrc(inPkt.getSourceMAC())
188 + .matchEthDst(inPkt.getDestinationMAC())
189 + .matchInport(context.inPacket().receivedFrom().port());
188 190
189 - FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(), 191 + TrafficTreatment.Builder treat = new DefaultTrafficTreatment.Builder();
190 - builder.build(), treat.build(), 0, appId); 192 + treat.setOutput(portNumber);
191 193
192 - flowRuleService.applyFlowRules(f); 194 + FlowRule f = new DefaultFlowRule(context.inPacket().receivedFrom().deviceId(),
195 + builder.build(), treat.build(), 0, appId);
196 +
197 + flowRuleService.applyFlowRules(f);
198 + }
193 } 199 }
194 200
195 } 201 }
......
...@@ -27,9 +27,11 @@ public class DefaultFlowRule implements FlowRule { ...@@ -27,9 +27,11 @@ public class DefaultFlowRule implements FlowRule {
27 27
28 private final ApplicationId appId; 28 private final ApplicationId appId;
29 29
30 + private boolean expired;
31 +
30 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector, 32 public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
31 TrafficTreatment treatment, int priority, FlowRuleState state, 33 TrafficTreatment treatment, int priority, FlowRuleState state,
32 - long life, long packets, long bytes, long flowId) { 34 + long life, long packets, long bytes, long flowId, boolean expired) {
33 this.deviceId = deviceId; 35 this.deviceId = deviceId;
34 this.priority = priority; 36 this.priority = priority;
35 this.selector = selector; 37 this.selector = selector;
...@@ -37,7 +39,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -37,7 +39,7 @@ public class DefaultFlowRule implements FlowRule {
37 this.state = state; 39 this.state = state;
38 this.appId = ApplicationId.valueOf((int) (flowId >> 32)); 40 this.appId = ApplicationId.valueOf((int) (flowId >> 32));
39 this.id = FlowId.valueOf(flowId); 41 this.id = FlowId.valueOf(flowId);
40 - 42 + this.expired = expired;
41 this.life = life; 43 this.life = life;
42 this.packets = packets; 44 this.packets = packets;
43 this.bytes = bytes; 45 this.bytes = bytes;
...@@ -186,4 +188,9 @@ public class DefaultFlowRule implements FlowRule { ...@@ -186,4 +188,9 @@ public class DefaultFlowRule implements FlowRule {
186 .toString(); 188 .toString();
187 } 189 }
188 190
191 + @Override
192 + public boolean expired() {
193 + return expired;
194 + }
195 +
189 } 196 }
......
...@@ -111,4 +111,11 @@ public interface FlowRule { ...@@ -111,4 +111,11 @@ public interface FlowRule {
111 */ 111 */
112 long bytes(); 112 long bytes();
113 113
114 + /**
115 + * Indicates that this flow has expired at the device.
116 + *
117 + * @return true if it has expired, false otherwise
118 + */
119 + boolean expired();
120 +
114 } 121 }
......
...@@ -161,7 +161,11 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -161,7 +161,11 @@ implements FlowRuleService, FlowRuleProviderRegistry {
161 switch (stored.state()) { 161 switch (stored.state()) {
162 case ADDED: 162 case ADDED:
163 case PENDING_ADD: 163 case PENDING_ADD:
164 - frp.applyFlowRule(stored); 164 + if (flowRule.expired()) {
165 + event = store.removeFlowRule(flowRule);
166 + } else {
167 + frp.applyFlowRule(stored);
168 + }
165 break; 169 break;
166 case PENDING_REMOVE: 170 case PENDING_REMOVE:
167 case REMOVED: 171 case REMOVED:
......
...@@ -231,6 +231,7 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -231,6 +231,7 @@ public class ProxyArpManager implements ProxyArpService {
231 arp.setOpCode(ARP.OP_REPLY); 231 arp.setOpCode(ARP.OP_REPLY);
232 arp.setProtocolType(ARP.PROTO_TYPE_IP); 232 arp.setProtocolType(ARP.PROTO_TYPE_IP);
233 arp.setHardwareType(ARP.HW_TYPE_ETHERNET); 233 arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
234 +
234 arp.setProtocolAddressLength((byte) IpPrefix.INET_LEN); 235 arp.setProtocolAddressLength((byte) IpPrefix.INET_LEN);
235 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH); 236 arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
236 arp.setSenderHardwareAddress(h.mac().getAddress()); 237 arp.setSenderHardwareAddress(h.mac().getAddress());
...@@ -238,7 +239,7 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -238,7 +239,7 @@ public class ProxyArpManager implements ProxyArpService {
238 239
239 arp.setTargetProtocolAddress(((ARP) request.getPayload()) 240 arp.setTargetProtocolAddress(((ARP) request.getPayload())
240 .getSenderProtocolAddress()); 241 .getSenderProtocolAddress());
241 - arp.setSenderProtocolAddress(h.ipAddresses().iterator().next().toInt()); 242 + arp.setSenderProtocolAddress(h.ipAddresses().iterator().next().toRealInt());
242 eth.setPayload(arp); 243 eth.setPayload(arp);
243 return eth; 244 return eth;
244 } 245 }
...@@ -291,7 +292,6 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -291,7 +292,6 @@ public class ProxyArpManager implements ProxyArpService {
291 case DEVICE_MASTERSHIP_CHANGED: 292 case DEVICE_MASTERSHIP_CHANGED:
292 case DEVICE_SUSPENDED: 293 case DEVICE_SUSPENDED:
293 case DEVICE_UPDATED: 294 case DEVICE_UPDATED:
294 - case PORT_UPDATED:
295 // nothing to do in these cases; handled when links get reported 295 // nothing to do in these cases; handled when links get reported
296 break; 296 break;
297 case DEVICE_REMOVED: 297 case DEVICE_REMOVED:
...@@ -301,9 +301,12 @@ public class ProxyArpManager implements ProxyArpService { ...@@ -301,9 +301,12 @@ public class ProxyArpManager implements ProxyArpService {
301 } 301 }
302 break; 302 break;
303 case PORT_ADDED: 303 case PORT_ADDED:
304 + case PORT_UPDATED:
304 synchronized (externalPorts) { 305 synchronized (externalPorts) {
305 - externalPorts.put(device, event.port().number()); 306 + if (event.port().isEnabled()) {
306 - internalPorts.remove(device, event.port().number()); 307 + externalPorts.put(device, event.port().number());
308 + internalPorts.remove(device, event.port().number());
309 + }
307 } 310 }
308 break; 311 break;
309 case PORT_REMOVED: 312 case PORT_REMOVED:
......
...@@ -48,7 +48,7 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -48,7 +48,7 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
48 OFPacketOut.Builder builder = sw.factory().buildPacketOut(); 48 OFPacketOut.Builder builder = sw.factory().buildPacketOut();
49 OFAction act = buildOutput(outPort.getPortNumber()); 49 OFAction act = buildOutput(outPort.getPortNumber());
50 pktout = builder.setXid(pktin.getXid()) 50 pktout = builder.setXid(pktin.getXid())
51 - .setInPort(pktin.getInPort()) 51 + .setInPort(inport())
52 .setBufferId(pktin.getBufferId()) 52 .setBufferId(pktin.getBufferId())
53 .setActions(Collections.singletonList(act)) 53 .setActions(Collections.singletonList(act))
54 .build(); 54 .build();
...@@ -63,7 +63,7 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -63,7 +63,7 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
63 OFAction act = buildOutput(outPort.getPortNumber()); 63 OFAction act = buildOutput(outPort.getPortNumber());
64 pktout = builder.setXid(pktin.getXid()) 64 pktout = builder.setXid(pktin.getXid())
65 .setBufferId(OFBufferId.NO_BUFFER) 65 .setBufferId(OFBufferId.NO_BUFFER)
66 - .setInPort(pktin.getInPort()) 66 + .setInPort(inport())
67 .setActions(Collections.singletonList(act)) 67 .setActions(Collections.singletonList(act))
68 .setData(ethFrame.serialize()) 68 .setData(ethFrame.serialize())
69 .build(); 69 .build();
...@@ -88,10 +88,16 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext ...@@ -88,10 +88,16 @@ public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext
88 88
89 @Override 89 @Override
90 public Integer inPort() { 90 public Integer inPort() {
91 + return inport().getPortNumber();
92 + }
93 +
94 +
95 + private OFPort inport() {
96 + //FIXME: this has to change in fucking loxi
91 try { 97 try {
92 - return pktin.getInPort().getPortNumber(); 98 + return pktin.getInPort();
93 } catch (UnsupportedOperationException e) { 99 } catch (UnsupportedOperationException e) {
94 - return pktin.getMatch().get(MatchField.IN_PORT).getPortNumber(); 100 + return pktin.getMatch().get(MatchField.IN_PORT);
95 } 101 }
96 } 102 }
97 103
......
...@@ -651,7 +651,7 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { ...@@ -651,7 +651,7 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
651 * @param error The error message 651 * @param error The error message
652 */ 652 */
653 protected void logError(OFChannelHandler h, OFErrorMsg error) { 653 protected void logError(OFChannelHandler h, OFErrorMsg error) {
654 - log.debug("{} from switch {} in state {}", 654 + log.info("{} from switch {} in state {}",
655 new Object[] { 655 new Object[] {
656 error, 656 error,
657 h.getSwitchInfoString(), 657 h.getSwitchInfoString(),
......
...@@ -6,6 +6,7 @@ import java.util.Collections; ...@@ -6,6 +6,7 @@ import java.util.Collections;
6 import java.util.List; 6 import java.util.List;
7 7
8 import org.onlab.onos.openflow.controller.Dpid; 8 import org.onlab.onos.openflow.controller.Dpid;
9 +import org.onlab.onos.openflow.controller.RoleState;
9 import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch; 10 import org.onlab.onos.openflow.controller.driver.AbstractOpenFlowSwitch;
10 import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver; 11 import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriver;
11 import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriverFactory; 12 import org.onlab.onos.openflow.controller.driver.OpenFlowSwitchDriverFactory;
...@@ -61,6 +62,11 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory { ...@@ -61,6 +62,11 @@ public final class DriverManager implements OpenFlowSwitchDriverFactory {
61 return new AbstractOpenFlowSwitch(dpid, desc) { 62 return new AbstractOpenFlowSwitch(dpid, desc) {
62 63
63 @Override 64 @Override
65 + public void setRole(RoleState state) {
66 + this.role = RoleState.MASTER;
67 + }
68 +
69 + @Override
64 public void write(List<OFMessage> msgs) { 70 public void write(List<OFMessage> msgs) {
65 channel.write(msgs); 71 channel.write(msgs);
66 } 72 }
......
...@@ -73,7 +73,7 @@ public class FlowModBuilder { ...@@ -73,7 +73,7 @@ public class FlowModBuilder {
73 List<OFAction> actions = buildActions(); 73 List<OFAction> actions = buildActions();
74 74
75 //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?
76 - OFFlowMod fm = factory.buildFlowModify() 76 + OFFlowMod fm = factory.buildFlowAdd()
77 .setCookie(U64.of(cookie.value())) 77 .setCookie(U64.of(cookie.value()))
78 .setBufferId(OFBufferId.NO_BUFFER) 78 .setBufferId(OFBufferId.NO_BUFFER)
79 .setActions(actions) 79 .setActions(actions)
......
...@@ -18,6 +18,7 @@ import org.onlab.packet.IpPrefix; ...@@ -18,6 +18,7 @@ import org.onlab.packet.IpPrefix;
18 import org.onlab.packet.MacAddress; 18 import org.onlab.packet.MacAddress;
19 import org.onlab.packet.VlanId; 19 import org.onlab.packet.VlanId;
20 import org.projectfloodlight.openflow.protocol.OFFlowRemoved; 20 import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
21 +import org.projectfloodlight.openflow.protocol.OFFlowRemovedReason;
21 import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; 22 import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
22 import org.projectfloodlight.openflow.protocol.action.OFAction; 23 import org.projectfloodlight.openflow.protocol.action.OFAction;
23 import org.projectfloodlight.openflow.protocol.action.OFActionOutput; 24 import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
...@@ -70,14 +71,15 @@ public class FlowRuleBuilder { ...@@ -70,14 +71,15 @@ public class FlowRuleBuilder {
70 buildSelector(), buildTreatment(), stat.getPriority(), 71 buildSelector(), buildTreatment(), stat.getPriority(),
71 FlowRuleState.ADDED, stat.getDurationNsec() / 1000000, 72 FlowRuleState.ADDED, stat.getDurationNsec() / 1000000,
72 stat.getPacketCount().getValue(), stat.getByteCount().getValue(), 73 stat.getPacketCount().getValue(), stat.getByteCount().getValue(),
73 - stat.getCookie().getValue()); 74 + stat.getCookie().getValue(), false);
74 } else { 75 } else {
75 // TODO: revisit potentially. 76 // TODO: revisit potentially.
76 return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), 77 return new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)),
77 buildSelector(), null, removed.getPriority(), 78 buildSelector(), null, removed.getPriority(),
78 FlowRuleState.REMOVED, removed.getDurationNsec() / 1000000, 79 FlowRuleState.REMOVED, removed.getDurationNsec() / 1000000,
79 removed.getPacketCount().getValue(), removed.getByteCount().getValue(), 80 removed.getPacketCount().getValue(), removed.getByteCount().getValue(),
80 - removed.getCookie().getValue()); 81 + removed.getCookie().getValue(),
82 + removed.getReason() == OFFlowRemovedReason.IDLE_TIMEOUT.ordinal());
81 } 83 }
82 } 84 }
83 85
......
...@@ -158,7 +158,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -158,7 +158,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
158 case BARRIER_REPLY: 158 case BARRIER_REPLY:
159 case ERROR: 159 case ERROR:
160 default: 160 default:
161 - log.warn("Unhandled message type: {}", msg.getType()); 161 + log.debug("Unhandled message type: {}", msg.getType());
162 } 162 }
163 163
164 } 164 }
......
...@@ -131,7 +131,7 @@ public class LinkDiscovery implements TimerTask { ...@@ -131,7 +131,7 @@ public class LinkDiscovery implements TimerTask {
131 } 131 }
132 timeout = Timer.getTimer().newTimeout(this, 0, 132 timeout = Timer.getTimer().newTimeout(this, 0,
133 TimeUnit.MILLISECONDS); 133 TimeUnit.MILLISECONDS);
134 - this.log.debug("Started discovery manager for switch {}", 134 + this.log.info("Started discovery manager for switch {}",
135 sw.getId()); 135 sw.getId());
136 136
137 } 137 }
......
1 package org.onlab.onos.provider.of.packet.impl; 1 package org.onlab.onos.provider.of.packet.impl;
2 2
3 -import static org.onlab.onos.openflow.controller.RoleState.SLAVE;
4 import static org.slf4j.LoggerFactory.getLogger; 3 import static org.slf4j.LoggerFactory.getLogger;
5 4
6 import java.nio.ByteBuffer; 5 import java.nio.ByteBuffer;
...@@ -95,9 +94,6 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr ...@@ -95,9 +94,6 @@ public class OpenFlowPacketProvider extends AbstractProvider implements PacketPr
95 if (sw == null) { 94 if (sw == null) {
96 log.warn("Device {} isn't available?", devId); 95 log.warn("Device {} isn't available?", devId);
97 return; 96 return;
98 - } else if (sw.getRole().equals(SLAVE)) {
99 - log.warn("Can't write to Device {} as slave", devId);
100 - return;
101 } 97 }
102 98
103 Ethernet eth = new Ethernet(); 99 Ethernet eth = new Ethernet();
......
...@@ -140,12 +140,12 @@ public class OpenFlowPacketProviderTest { ...@@ -140,12 +140,12 @@ public class OpenFlowPacketProviderTest {
140 sw.sent.clear(); 140 sw.sent.clear();
141 141
142 //wrong Role 142 //wrong Role
143 - sw.setRole(RoleState.SLAVE); 143 + //sw.setRole(RoleState.SLAVE);
144 - provider.emit(passPkt); 144 + //provider.emit(passPkt);
145 - assertEquals("invalid switch", sw, controller.current); 145 + //assertEquals("invalid switch", sw, controller.current);
146 - assertEquals("message sent incorrectly", 0, sw.sent.size()); 146 + //assertEquals("message sent incorrectly", 0, sw.sent.size());
147 147
148 - sw.setRole(RoleState.MASTER); 148 + //sw.setRole(RoleState.MASTER);
149 149
150 //missing switch 150 //missing switch
151 OutboundPacket swFailPkt = outPacket(DID_MISSING, TR, eth); 151 OutboundPacket swFailPkt = outPacket(DID_MISSING, TR, eth);
......
...@@ -180,6 +180,15 @@ public final class IpPrefix { ...@@ -180,6 +180,15 @@ public final class IpPrefix {
180 return address; 180 return address;
181 } 181 }
182 182
183 + public int toRealInt() {
184 + int val = 0;
185 + for (int i = 0; i < octets.length; i++) {
186 + val <<= 8;
187 + val |= octets[i] & 0xff;
188 + }
189 + return val;
190 + }
191 +
183 /** 192 /**
184 * Helper for computing the mask value from CIDR. 193 * Helper for computing the mask value from CIDR.
185 * 194 *
......