Skip to content

Commit 27c5b31

Browse files
committed
Merge branch 'stanford19' of github.com:opennetworkinglab/ngsdn-tutorial into stanford19
2 parents 6fd0080 + a117d9c commit 27c5b31

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

EXERCISE-5.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,18 @@ bar. If you are using the tutorial VM, open up a browser (e.g. Firefox) to
345345
346346
To toggle showing hosts on the topology view, press `H` on your keyboard.
347347
348+
### Extra Credit
349+
350+
The current solution drops unmatched traffic that is not an ARP or NDP packet.
351+
This is to prevent masking bugs your unicast forwarding code as you develop it.
352+
353+
However, traditional bridging requires that unmatched traffic be flooded to all
354+
interfaces except the ingress one. We've provided some starter code that adds a
355+
rule to flood unmatched traffic. You will need to complete the implementation of `insertUnmatchedBridgingFlowRule()` and then call this method when the device is
356+
set up (in `setUpDevice()`).
357+
358+
Look for `TODO EXERCISE 5 EXTRA CREDIT` to see where you will need to change code.
359+
348360
## Congratulations
349361
350362
You have completed the fifth exercise! Now your fabric is capable of forwarding

app/src/main/java/org/onosproject/ngsdn/tutorial/L2BridgingComponent.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ private void setUpDevice(DeviceId deviceId) {
154154
}
155155
insertMulticastGroup(deviceId);
156156
insertMulticastFlowRules(deviceId);
157+
// *** TODO EXERCISE 5 EXTRA CREDIT
158+
// Uncomment the following line after you have implemented the method:
159+
// insertUnmatchedBridgingFlowRule(deviceId);
157160
}
158161

159162
/**
@@ -247,6 +250,54 @@ private void insertMulticastFlowRules(DeviceId deviceId) {
247250
flowRuleService.applyFlowRules(rule1, rule2);
248251
}
249252

253+
/**
254+
* Insert flow rule that matches all unmatched ethernet traffic. This
255+
* will implement the traditional briding behavior that floods all
256+
* unmatched traffic.
257+
* <p>
258+
* This method will be called at component activation for each device
259+
* (switch) known by ONOS, and every time a new device-added event is
260+
* captured by the InternalDeviceListener defined below.
261+
*
262+
* @param deviceId device ID where to install the rules
263+
*/
264+
private void insertUnmatchedBridgingFlowRule(DeviceId deviceId) {
265+
266+
log.info("Adding L2 multicast rules on {}...", deviceId);
267+
268+
// *** TODO EXERCISE 5 EXTRA CREDIT
269+
// Modify P4Runtime entity names to match content of P4Info file (look
270+
// for the fully qualified name of tables, match fields, and actions.
271+
// ---- START SOLUTION ----
272+
273+
// Match unmatched traffic - Match ternary **:**:**:**:**:**
274+
final PiCriterion unmatchedTrafficCriterion = PiCriterion.builder()
275+
.matchTernary(
276+
PiMatchFieldId.of("MODIFY ME"),
277+
MacAddress.valueOf("MODIFY ME").toBytes(),
278+
MacAddress.valueOf("MODIFY ME").toBytes())
279+
.build();
280+
281+
// Action: set multicast group id
282+
final PiAction setMcastGroupAction = PiAction.builder()
283+
.withId(PiActionId.of("MODIFY ME"))
284+
.withParameter(new PiActionParam(
285+
PiActionParamId.of("MODIFY ME"),
286+
DEFAULT_BROADCAST_GROUP_ID))
287+
.build();
288+
289+
// Build flow rule.
290+
final String tableId = "MODIFY ME";
291+
// ---- END SOLUTION ----
292+
293+
final FlowRule rule = Utils.buildFlowRule(
294+
deviceId, appId, tableId,
295+
unmatchedTrafficCriterion, setMcastGroupAction);
296+
297+
// Insert rules.
298+
flowRuleService.applyFlowRules(rule);
299+
}
300+
250301
/**
251302
* Insert flow rules to forward packets to a given host located at the given
252303
* device and port.

solution/app/src/main/java/org/onosproject/ngsdn/tutorial/AppConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class AppConstants {
2424
public static final PiPipeconfId PIPECONF_ID = new PiPipeconfId("org.onosproject.ngsdn-tutorial");
2525

2626
public static final int DEFAULT_FLOW_RULE_PRIORITY = 10;
27+
public static final int FALLBACK_FLOW_RULE_PRIORITY = 5;
2728
public static final int INITIAL_SETUP_DELAY = 2; // Seconds.
2829
public static final int CLEAN_UP_DELAY = 2000; // milliseconds
2930
public static final int DEFAULT_CLEAN_UP_RETRY_TIMES = 10;

solution/app/src/main/java/org/onosproject/ngsdn/tutorial/L2BridgingComponent.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ private void setUpDevice(DeviceId deviceId) {
154154
}
155155
insertMulticastGroup(deviceId);
156156
insertMulticastFlowRules(deviceId);
157+
// *** TODO EXERCISE 5 EXTRA CREDIT
158+
// Uncomment the following line after you have implemented the method:
159+
insertUnmatchedBridgingFlowRule(deviceId);
157160
}
158161

159162
/**
@@ -247,6 +250,54 @@ private void insertMulticastFlowRules(DeviceId deviceId) {
247250
flowRuleService.applyFlowRules(rule1, rule2);
248251
}
249252

253+
/**
254+
* Insert flow rule that matches all unmatched ethernet traffic. This
255+
* will implement the traditional briding behavior that floods all
256+
* unmatched traffic.
257+
* <p>
258+
* This method will be called at component activation for each device
259+
* (switch) known by ONOS, and every time a new device-added event is
260+
* captured by the InternalDeviceListener defined below.
261+
*
262+
* @param deviceId device ID where to install the rules
263+
*/
264+
private void insertUnmatchedBridgingFlowRule(DeviceId deviceId) {
265+
266+
log.info("Adding L2 multicast rules on {}...", deviceId);
267+
268+
// *** TODO EXERCISE 5 EXTRA CREDIT
269+
// Modify P4Runtime entity names to match content of P4Info file (look
270+
// for the fully qualified name of tables, match fields, and actions.
271+
// ---- START SOLUTION ----
272+
273+
// Match unmatched traffic - Match ternary **:**:**:**:**:**
274+
final PiCriterion unmatchedTrafficCriterion = PiCriterion.builder()
275+
.matchTernary(
276+
PiMatchFieldId.of("hdr.ethernet.dst_addr"),
277+
MacAddress.valueOf("00:00:00:00:00:00").toBytes(),
278+
MacAddress.valueOf("00:00:00:00:00:00").toBytes())
279+
.build();
280+
281+
// Action: set multicast group id
282+
final PiAction setMcastGroupAction = PiAction.builder()
283+
.withId(PiActionId.of("IngressPipeImpl.set_multicast_group"))
284+
.withParameter(new PiActionParam(
285+
PiActionParamId.of("gid"),
286+
DEFAULT_BROADCAST_GROUP_ID))
287+
.build();
288+
289+
// Build flow rule.
290+
final String tableId = "IngressPipeImpl.l2_ternary_table";
291+
// ---- END SOLUTION ----
292+
293+
final FlowRule rule = Utils.buildFlowRule(
294+
deviceId, appId, tableId,
295+
unmatchedTrafficCriterion, setMcastGroupAction);
296+
297+
// Insert rules.
298+
flowRuleService.applyFlowRules(rule);
299+
}
300+
250301
/**
251302
* Insert flow rules to forward packets to a given host located at the given
252303
* device and port.

0 commit comments

Comments
 (0)