s2 $PATHS[] = ['s1', 's2']; $PATHS[] = ['s1', 's3', 's2']; $PATHS[] = ['s1', 's4', 's3', 's2']; break; case 's3': // s1 -> s3 $PATHS[] = ['s1', 's3']; $PATHS[] = ['s1', 's2','s3']; $PATHS[] = ['s1', 's4','s3']; break; case 's4': // s1 -> s4 $PATHS[] = ['s1', 's4']; $PATHS[] = ['s1', 's3', 's4']; $PATHS[] = ['s1', 's2', 's3', 's4']; break; } break; case 's2': switch($dst) { case 's1': // s2 -> s1 $PATHS[] = ['s2', 's1']; $PATHS[] = ['s2', 's3', 's1']; $PATHS[] = ['s2', 's3', 's4', 's1']; break; case 's3': // s2 -> s3 $PATHS[] = ['s2', 's3']; $PATHS[] = ['s2', 's1', 's3']; $PATHS[] = ['s2', 's1', 's4', 's3']; break; case 's4': // s2 -> s4 $PATHS[] = ['s2', 's3', 's4']; $PATHS[] = ['s2', 's1', 's4']; $PATHS[] = ['s2', 's1', 's3', 's4']; break; } break; case 's3': switch($dst) { case 's1': // s3 -> s1 $PATHS[] = ['s3', 's1']; $PATHS[] = ['s3', 's2', 's1']; $PATHS[] = ['s3', 's4', 's1']; break; case 's2': // s3 -> s2 $PATHS[] = ['s3', 's2']; $PATHS[] = ['s3', 's1', 's2']; $PATHS[] = ['s3', 's4', 's1', 's2']; break; case 's4': // s3 -> s4 $PATHS[] = ['s3', 's4']; $PATHS[] = ['s3', 's1', 's4']; $PATHS[] = ['s3', 's2', 's1', 's4']; break; } break; case 's4': switch($dst) { case 's1': // s4 -> s1 $PATHS[] = ['s4', 's1']; $PATHS[] = ['s4', 's3', 's1']; $PATHS[] = ['s4', 's3', 's2', 's1']; break; case 's2': // s4 -> s2 $PATHS[] = ['s4', 's1', 's2']; $PATHS[] = ['s4', 's3', 's2']; $PATHS[] = ['s4', 's1', 's3', 's2']; $PATHS[] = ['s4', 's3', 's1', 's2']; break; case 's3': // s4 -> s3 $PATHS[] = ['s4', 's3']; $PATHS[] = ['s4', 's1', 's3']; $PATHS[] = ['s4', 's1', 's2', 's3']; break; } break; } shuffle($PATHS); $PATH = array_pop($PATHS); // randomize paths and pick one $PATH_text = ""; for($i = 0; $i < count($PATH); $i++) { // create string from path $PATH_text .= $PATH[$i]; if($i+1 != count($PATH)) { $PATH_text .= " -> "; } } return [$PATH, $PATH_text]; } /* Problem Instance */ $nodes = ['s1', 's2', 's3', 's4']; shuffle($nodes); // Subnets connected to each router $IP_List = ['s1'=>'128.119/16', 's2'=>'128.120/16', 's3'=>'128.121/16', 's4'=>'128.122/16']; // Interface value based on src,dst $interfaces = ['s1'=>['s1'=>'1', 's2'=>'2', 's3'=>'3', 's4'=>'4'], 's2'=>['s1'=>'3', 's2'=>'1','s3'=>'2'], 's3'=>['s1'=>'3', 's2'=>'4', 's3'=>'1', 's4'=>'2'], 's4'=>['s1'=>'2', 's3'=>'3', 's4'=>'1']]; // matches src, dst to src interface // Bulletpoint 1 $src1 = array_pop($nodes); $dst1 = array_pop($nodes); $path1_raw = generatePath($src1, $dst1); $path1 = $path1_raw[0]; $path1_text = $path1_raw[1]; $extra1_1 = ""; if(rand(0, 1) == 1) { $protocol1 = rand(0, 1) == 1 ? "HTTP" : "TCP"; $extra1_1 = " Assume that at {$src1} that only {$protocol1} traffic is allowed to exit the network."; } $extra1_2 = ""; if(rand(0, 1) == 1) { $protocol2 = rand(0, 1) == 1 ? "HTTP" : "TCP"; $extra1_2 = " Assume that at {$dst1} that only {$protocol2} traffic is allowed to enter the network."; } $b1_text = "Packets coming from the source network attached to {$src1} and destined to the network attached to {$dst1} should be forwarded along the path: {$path1_text}.{$extra1_1}{$extra1_2}"; // Bulletpoint 2 $b2_text = ""; $src2 = array_pop($nodes); // reset nodes, remove src from list, and grab random other node as dst2 $nodes = ['s1', 's2', 's3', 's4']; unset($nodes[array_search($src2, $nodes)]); shuffle($nodes); $dst2 = array_pop($nodes); $path2_raw = generatePath($src2, $dst2); $path2 = $path2_raw[0]; $path2_text = $path2_raw[1]; // make sure path picked is different from above one (only used in one of the two cases below) while(true) { $path3_raw = generatePath($src2, $dst2); if($path3_raw[1] !== $path2_raw[1]) { break; } } $path3 = $path3_raw[0]; $path3_text = $path3_raw[1]; $b2_text = "TCP packets coming from the source network attached to {$src2} and destined to the network attached to {$dst2} should be forwarded along the path: {$path2_text}. UDP packets coming from the source network attached to {$src2} and destined to the network attached to {$dst2} should be forwarded along the different path: {$path3_text}"; $b = rand(0, 1); // chooses which bullet point to use if($b == 0) { // first bullet point $b_text = $b1_text; } else { // second bullet point $b_text = $b2_text; } /* Problem Statement */ $header_text = <<< text_tag

Openflow Flow Tables

Consider the 4-router network shown below, where packet forwarding is controlled by flow tables (e.g., configured via OpenFlow in an SDN controller), rather than by a forwarding table computed by a routing algorithm. The addresses of networks attached to each of the router is also shown. The interfaces at each of the routers are also as indicated.


Suppose we want the following forwarding behavior of packets to be implemented:

Complete the match-plus-action tables in each of the routers, s1, s2, s3, and s4, that implement these forwarding behaviors. Your rules should be as strict as possible (should only allow these behaviors, and no other forwarding behaviors). You can assume that any packet arriving at a router that does not match a rule in that table will be dropped.


text_tag; echo $header_text; /* Dependencies */ require('questions.php'); require('questionList.php'); require('solution.php'); /* Questions and Answers */ $nodes = ['s1', 's2', 's3', 's4']; for($i = 0; $i < 4; $i++) { // iterate through all routers $router = $nodes[$i]; if($b == 0) { // first bullet point used $index = array_search($router, $path1); if($index !== false) { // router is in path 1 $question_list[] = "For router {$router}, what should the value of the 'IP Src' be? Pick either a specific address (including CIDR), any, or none"; $question_list[] = "For router {$router}, what should the value of the 'IP Dst' be? Pick either a specific address (including CIDR), any, or none"; $question_list[] = "For router {$router}, what should the value of the 'Src Port' be? Pick either a specific port, or any"; $question_list[] = "For router {$router}, what should the value of the 'Dst Port' be? Pick either a specific port, or any"; $question_list[] = "For router {$router}, what should the value of the 'IP Proto' be? Pick either TCP, UDP, or any"; $question_list[] = "For router {$router}, what should the action of the rule be? Some examples include forward, allow, deny, etc"; $question_list[] = "For router {$router}, what interface should the packets be forwarded to?"; $answers[] = $IP_List[$src1]; // src ip $answers[] = $IP_List[$dst1]; // dst ip if($router == $src1) { // handle incoming IP $answers[] = "Any"; // src port if($extra1_1 !== "") { if($protocol1 == "HTTP") { $answers[] = "80"; // dst port } else { $answers[] = "Any"; // dst port } $answers[] = "TCP"; // protocol } else { $answers[] = "Any"; // dst port $answers[] = "Any"; // protocol } $answers[] = "Forward"; // action $answers[] = $interfaces[$router][$path1[$index+1]]; // interface } else if($router == $dst1) { if($extra1_2 !== "") { if($protocol2 == "HTTP") { $answers[] = "80"; // src port } else { $answers[] = "Any"; // src port } $answers[] = "Any"; // dst port $answers[] = "TCP"; // protocol } else { $answers[] = "Any"; // src port $answers[] = "Any"; // dst port $answers[] = "Any"; // protocol } $answers[] = "Forward"; // action $answers[] = $interfaces[$router][$router]; // interface } else { $answers[] = "Any"; // src port $answers[] = "Any"; // dst port $answers[] = "Any"; // protocol $answers[] = "Forward"; // action $answers[] = $interfaces[$router][$path1[$index+1]]; // interface } } } else { // second bullet point used $index = array_search($router, $path2); if($index !== false) { // router is in path 2 $question_list[] = "For router {$router}, what should the value of the 'IP Src' be? Pick either a specific address (including CIDR), any, or none"; $question_list[] = "For router {$router}, what should the value of the 'IP Dst' be? Pick either a specific address (including CIDR), any, or none"; $question_list[] = "For router {$router}, what should the value of the 'Src Port' be? Pick either a specific port, or any"; $question_list[] = "For router {$router}, what should the value of the 'Dst Port' be? Pick either a specific port, or any"; $question_list[] = "For router {$router}, what should the value of the 'IP Proto' be? Pick either TCP, UDP, or any"; $question_list[] = "For router {$router}, what should the action of the rule be? Some examples include forward, allow, deny, etc"; $question_list[] = "For router {$router}, what interface should the packets be forwarded to?"; $answers[] = $IP_List[$src2]; // ip src $answers[] = $IP_List[$dst2]; // ip dst $answers[] = "Any"; // src port $answers[] = "Any"; // dst port $answers[] = "TCP"; // protocol $answers[] = "Forward"; // action if($router == $dst2) { $answers[] = $interfaces[$router][$router]; // interface } else { $answers[] = $interfaces[$router][$path2[$index+1]]; // interface } } $index = array_search($router, $path3); if($index !== false) { // router is in path 3 $question_list[] = "For router {$router}, what should the value of the 'IP Src' be? Pick either a specific address (including CIDR), any, or none"; $question_list[] = "For router {$router}, what should the value of the 'IP Dst' be? Pick either a specific address (including CIDR), any, or none"; $question_list[] = "For router {$router}, what should the value of the 'Src Port' be? Pick either a specific port, or any"; $question_list[] = "For router {$router}, what should the value of the 'Dst Port' be? Pick either a specific port, or any"; $question_list[] = "For router {$router}, what should the value of the 'IP Proto' be? Pick either TCP, UDP, or any"; $question_list[] = "For router {$router}, what should the action of the rule be? Some examples include forward, allow, deny, etc"; $question_list[] = "For router {$router}, what interface should the packets be forwarded to?"; $answers[] = $IP_List[$src2]; // ip src $answers[] = $IP_List[$dst2]; // ip dst $answers[] = "Any"; // src port $answers[] = "Any"; // dst port $answers[] = "UDP"; // protocol $answers[] = "Forward"; // action if($router == $dst2) { $answers[] = $interfaces[$router][$router]; // interface } else { $answers[] = $interfaces[$router][$path3[$index+1]]; // interface } } } } /* Interactive Questions */ for($i = 0; $i < count($question_list); $i++) { $hint; switch($i%7) { case 0: $hint = 'The source will be the subnet of where the packet originated'; break; case 1: $hint = 'The destination will be the subnet of where the packet is going, which doesn\'t change as the packet travels'; break; case 2: $hint = 'Unless the router needs to block packets from entering based on content, the src port will be \'any\''; break; case 3: $hint = 'Unless the router needs to block packets from exiting based on content, the dst port will be \'any\''; break; case 4: $hint = 'Depending on if this router is regulating content entering or exiting, this will be the protocol associated with the content or \'any\''; break; case 5: $hint = 'Since the default behavior of a router is to drop an unmatched packet, the action for this rule will be \'forward\''; break; case 6: $hint = 'The interface will be the one attached to the next router in the packet\'s path'; break; } $questions[] = new Question('string', $question_list[$i], $answers[$i], $hint, $answers[$i]); } /* Create Problem */ // Shows list of questions when 'show questions' is clicked generateQuestionList($question_list); // Solution text $solution = ""; for($i = 0; $i < count($answers)/7; $i++) { $ri = ($i*7); // rule index $rn = $i + 1; // counts number of rules // question index (e.g rule 1 is questions 1-7) $qs = $ri + 1; // question start $qe = $ri + 7; // question end $q_index = "Q{$qs}-Q{$qe}"; $solution .= "({$q_index}) Rule {$rn}. | IP_Src={$answers[$ri]}, IP_Dst={$answers[$ri+1]}, Src_Port={$answers[$ri+2]}, Dst_Port={$answers[$ri+3]}, IP_Protocol={$answers[$ri+4]}, Action={$answers[$ri+5]}({$answers[$ri+6]}) |"; $solution .= "

"; } $solution = substr($solution, 0, -5); // remove last
from solution text // Show solution text when 'show solution' is clicked generateSolution($solution); // Create questions for user to answer createQuestions($questions); /* Do the Footer */ require('footer_v3.htm'); ?>