Codementor Events

Computer Network help

Published Oct 28, 2018

I have this code to implement Mininet.

  • Write a simple program (in Java/C/Python) which takes as input depth and fanout arguments, and produces the forwarding rules (in the dpctl format) which allow communication between all of the hosts in Mininet for a topology with that depth and fanout. In other words, after installing the forwarding rules, pingall should succeed in Mininet.

https://d1b10bmlvqabco.cloudfront.net/attach/jkyk8qr5l4a47b/h0bnte7gjys6r8/jniec8qr39ld/Forwarding.java

and here forwarding rules in the dpctl format just include them in code.

https://pastebin.com/4sz7D5rw

// you can add code to forwarding/Forwarding.java, which already has all the functionality to compute the tree with given depth/fanout etc.

// in that file, you'll find the following line:

LinkedList<TreeNode> leaves = root.getLeaves(); // these are the HOSTS

// your code should be placed immediately after that line

// there is a variable called "root", which is the ROOT NODE of the tree (in the above example, the root is "s1"

/* Step 1: write a function called computePath which finds a PATH from a source node to a destination node:

List<Interface> computePath(TreeNode src, TreeNode dst) {
// first, compute the list of ancestors of src, by using src.getParent() and/or src.getParentInterface(). You will know when you've reached the root node when getParent() returns null.

// do the same thing for dst (compute a list of its ancestors)

// find the first index i=0,1,2,... where srcAncestors[i] = dstAncestors[i]

// this node is the "least common ancestor" of src and dst

// the path from src to dst is then [srcAncestors[0], ..., srcAncestors[i], dstAncestors[i-1], ..., dstAncestors[0]]

// for each node along this path, you need to create a new Interface(in, s, out), where in is the input interface and out is the output interface and s is the node

// EXAMPLE: for the above path [s2,s1,s3] in the picture, you would create the list:
// [new Interface(1,s2,3), new Interface(1,s1,2), new Interface(3,s3,1)]

// there are methods x.getParentInterface() and x.getChildInterface(y) which let you get the ID for a parent interface of node x, and child interface for child y of x, respectively.

// finally, return this list of interfaces
}
*/

/* Step 2: write a function called printPath which takes a computed path, and prints the forwarding rules, as described in the Lab3 writeup

void printPath(TreeNode src, TreeNode dst, List<Interface> path) {
for(Interface i : path) {
int inputInterface = i.iface;
int outputInterface = i.getIface2();
Node node = i.node;

  // you now simply print a forwarding rule(s) for that node, and those interfaces

  // the Lab3 writeup shows you exactly which rules you would need to use for each hop along an example path

  // remember that traffic needs to be able to flow in BOTH directions through this node,
  // and you need to allow both IP and ARP packets

}
}
*/

/* Step 3: go through each pair of (src,dst) hosts, and compute/print the path:

for(TreeNode src : leaves) {
for(TreeNode dst : leaves) {
if(src.id < dst.id) {
List<Interface> path = computePath(src, dst);
printPath(src, dst, path);
}
}
}
*/

Discover and read more posts from stephan lee
get started