Protocol for Data Networks (aka Advanced Topics in Networking)

Similar documents
Exercise 1. Contents. 1. Introduction. (a) Installing the required software

Tutorial. Reference for more thorough Mininet walkthrough if desired

Lab 7: Software Defined Networking

Programming Assignment 2: Using Mininet and Mininet Python API: Instructions

Project 4: SDNs Due: 11:59 PM, Dec 11, 2014

LAB THREE STATIC ROUTING

How To Understand and Configure Your Network for IntraVUE

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

I. ADDITIONAL EVALUATION RESULTS. A. Environment

Developing OpenDaylight Apps with MD-SAL. J. Medved, E. Warnicke, A. Tkacik. R. Varga Cisco Sample App: M. Rehak, Cisco February 04, 2014

Project 2: Firewall Design (Phase I)

Lab 1: Introduction to the network lab


Information Security Training. Assignment 1 Networking

Make a folder named Lab3. We will be using Unix redirection commands to create several output files in that folder.

How Do I Upgrade Firmware and Save Configurations on PowerConnect Switches?

Hadoop Installation MapReduce Examples Jake Karnes

Frenetic: A Programming Language for OpenFlow Networks

Flow Analysis Versus Packet Analysis. What Should You Choose?

Modular SDN Programming with Pyretic

TCP Labs. WACREN Network Monitoring and Measurement Workshop Antoine Delvaux perfsonar developer

Procedure: You can find the problem sheet on Drive D: of the lab PCs. Part 1: Router & Switch

Composing Software-Defined Networks

SOA Software: Troubleshooting Guide for Agents

Software Defined Networking

How to install PowerChute Network Shutdown on VMware ESXi 3.5, 4.0 and 4.1

SSVP SIP School VoIP Professional Certification

Ciphermail Gateway Separate Front-end and Back-end Configuration Guide

BASIC ANALYSIS OF TCP/IP NETWORKS

: Interconnecting Cisco Networking Devices Part 1 v2.0 (ICND1)

This chapter describes how to set up and manage VPN service in Mac OS X Server.

Moxa Device Manager 2.3 User s Manual

Linux Firewalls (Ubuntu IPTables) II

Installation Guide Supplement

Cisco Configuring Commonly Used IP ACLs

20. Switched Local Area Networks

Network Traffic Analysis

Procedure: You can find the problem sheet on Drive D: of the lab PCs. 1. IP address for this host computer 2. Subnet mask 3. Default gateway address

What is VLAN Routing?

Intrusion Detection and Prevention: Network and IDS Configuration and Monitoring using Snort

Top-Down Network Design

How To Set Up A Network Map In Linux On A Ubuntu 2.5 (Amd64) On A Raspberry Mobi) On An Ubuntu (Amd66) On Ubuntu 4.5 On A Windows Box

AlienVault Unified Security Management (USM) 4.x-5.x. Deploying HIDS Agents to Linux Hosts

Load Balancing Clearswift Secure Web Gateway

Emulation of Software Defined Networks Using Mininet in Different Simulation Environments

Blue Coat Security First Steps Transparent Proxy Deployments

Cisco Change Management: Best Practices White Paper

Quick Start for Network Agent. 5-Step Quick Start. What is Network Agent?

Lab Diagramming Intranet Traffic Flows

WhatsUpGold. v3.0. WhatsConnected User Guide

Using OpenFlow 1.3 RYU. SDN Framework. RYU project team

How to deploy console cable to connect WIAS-3200N and PC, to reset setting or check status via console

Apache CloudStack 4.x (incubating) Network Setup: excerpt from Installation Guide. Revised February 28, :32 pm Pacific

Quick Start for Network Agent. 5-Step Quick Start. What is Network Agent?

Symantec LiveUpdate Administrator. Getting Started Guide

Trouble Shooting SiteManager to GateManager access

ms-help://ms.technet.2005mar.1033/security/tnoffline/security/smbiz/winxp/fwgrppol...

MuL SDN Controller HOWTO for pre-packaged VM

Linking 2 Sites Together Using VPN How To

How To Test The Bandwidth Meter For Hyperv On Windows V (Windows) On A Hyperv Server (Windows V2) On An Uniden V2 (Amd64) Or V2A (Windows 2

CET442L Lab #2. IP Configuration and Network Traffic Analysis Lab

Packet Sniffing and Spoofing Lab

Exercise 4 MPLS router configuration

Getting Started With Delegated Administration

SDN, OpenFlow and the ONF

Digger Solutions. Intranet Open Source. Administrator s Guide

CCNA Discovery Networking for Homes and Small Businesses Student Packet Tracer Lab Manual

SolarWinds Certified Professional. Exam Preparation Guide

Platform as a Service and Container Clouds

Programmable Networking with Open vswitch

Accops HyWorks v2.5. Quick Start Guide. Last Update: 4/18/2016

High Availability Failover Optimization Tuning HA Timers PAN-OS 6.0.0

Chapter 10 Troubleshooting

Lab 1: Network Devices and Technologies - Capturing Network Traffic

Chapter 15: Advanced Networks

Evaluation guide. Vyatta Quick Evaluation Guide

Cassandra Installation over Ubuntu 1. Installing VMware player:

Chapter 7. Address Translation

Management Software. Web Browser User s Guide AT-S106. For the AT-GS950/48 Gigabit Ethernet Smart Switch. Version Rev.

OpenFlow and Software Defined Networking presented by Greg Ferro. OpenFlow Functions and Flow Tables

Network Programmability Using POX Controller

You can probably work with decimal. binary numbers needed by the. Working with binary numbers is time- consuming & error-prone.

Dos & DDoS Attack Signatures (note supplied by Steve Tonkovich of CAPTUS NETWORKS)

Configuring the Transparent or Routed Firewall

Implementing Network Address Translation and Port Redirection in epipe

Getting to know OpenFlow. Nick Rutherford Mariano Vallés

netkit lab MPLS VPNs with overlapping address spaces 1.0 S.Filippi, L.Ricci, F.Antonini Version Author(s)

iseries TCP/IP routing and workload balancing

Linux MPS Firewall Supplement

Sage 100 ERP. Installation and System Administrator s Guide

Packet Capture. Document Scope. SonicOS Enhanced Packet Capture

Free Dynamic DNS account you can use one of your choosing I like DynDNS but there's also No-IP and probably others.

Zarząd (7 osób) F inanse (13 osób) M arketing (7 osób) S przedaż (16 osób) K adry (15 osób)

Chapter 4 Customizing Your Network Settings

DEPLOYMENT GUIDE Version 1.2. Deploying the BIG-IP System v10 with Microsoft IIS 7.0 and 7.5

Craig Pelkie Bits & Bytes Programming, Inc. craig@web400.com

Transcription:

Protocol for Data Networks (aka Advanced Topics in Networking) Pyretic Programming Assignment Regivaldo Costa, Fernando Ramos Lisbon, January/2014

Contents 1. Pyretic Programming Assignment... 3 1.1. Overview... 3 1.2. Building the Pyretic Environment for VM or Not... 4 1.3. Verify Hub behavior with tcpdump... 5 1.4. Verify Switch behavior with tcpdump... 7 1.4.1. Useful Pyretic policies... 10 1.5. Assignment... 10 1.5.1. Background... 10 1.5.2. Network Topology... 10 1.5.3. Understanding the Code... 11 1.5.4. Testing your Code... 12 Bibliography... 13 [ 2 ]

1. Pyretic Programming Assignment In this exercise, you will be working with Pyretic, a new programmer friendly domain specific language embedded in Python. It provides a runtime system that enables programmers to specify network policies at a high level of abstraction, compose them together in a variety of ways, and execute them on abstract topologies. In this assignment you will be taken through the steps of writing network applications on Pyretic a hub and a layer 2 MAC learning application and testing them using Mininet. The purpose of this exercise is to show you that there is no single way of writing such applications. New runtime systems are being developed, which provide richer abstractions and tools to express your network applications. Pyretic is one such example. After the walkthrough you will be asked to reimplement and submit the Layer 2 firewall you encoded in POX in the last assignment using the higher level constructs offered by Pyretic. More details on creating and submitting the code will be provided later on in the instructions. So, as always, make sure that you follow each step carefully. 1.1. Overview The network you'll use in this exercise includes 3 hosts and a switch, this time with the Pyretic runtime to express your network applications. Figure 1: Topology for the Network under Test [ 3 ]

As mentioned above, Pyretic is a new language and system that enables modular programming by: Defining composition operators and a library of policies for forwarding and querying traffic. Pyretic's parallel composition operator allows multiple policies to operate on the same set of packets, while its sequential composition operator allows one policy to process packets after another. Pyretic enables each policy to operate on an abstract topology that implicitly constrains what the module can see and do. Pyretic provides a rich abstract packet model that allows programmers to extend packets with virtual fields that may be used to associate packets with highlevel metadata. For more details on Pyretic, see http://frenetic-lang.org/pyretic/. 1.2. Building the Pyretic Environment Instructions for creating a Pyretic VM from the Mininet VM using VirualBox: a) Download the official Mininet VM (instructions tested using mininet-2.1.0-130919-ubuntu-13.04- server amd64 and i386 images) b) Import into Virtual Box, in "Settings->Basic" set "Name" appropriately c) Install Python dependencies: $ sudo apt-get install python-dev python-pip screen hping3 $ sudo pip install networkx bitarray netaddr ipaddr pytest ipdb d) Patch asynchat Python dependency (addresses some, but not all, of the bugs in this library): $ wget https://raw.github.com/frenetic-lang/pyretic/master/pyretic/backend/patch/asynchat.py $ sudo mv asynchat.py /usr/lib/python2.7/ $ sudo chown root:root /usr/lib/python2.7/asynchat.py e) Install git subtree: $ git clone https://github.com/git/git.git $ pushd git/contrib/subtree/ $ make $ sudo install -m 755 git-subtree /usr/lib/git-core $ popd $ rm -rf git f) Clone the pyretic repository to your home directory $ cd ~ $ git clone git://github.com/frenetic-lang/pyretic.git [ 4 ]

g) Setup your environment variables EITHER by adding the following lines to end of.profile: export PATH=$PATH:$HOME/pyretic:$HOME/pox export PYTHONPATH=$HOME/pyretic:$HOME/mininet:$HOME/pox or by replacing your.profile $ rm.profile $ wget http://frenetic-lang.org/pyretic/useful/.profile $ chmod g-w.profile We will be using the Pyretic runtime system, so make sure that the default or POX controller is not running in the background. Also, confirm that the port 6633 used to communicate with OpenFlow switches by the runtime is not bounded: $ sudo fuser -k 6633/tcp This will kill any existing TCP connection, using this port. You should also run sudo mn -c and restart Mininet to make sure that everything is clean and using the faster kernel switch. From you Mininet console: mininet> exit $ sudo mn -c $ sudo mn --topo single,3 --mac --switch ovsk --controller remote The Pyretic runtime comes preinstalled with the provided VM image. 1.3. Verify Hub behavior with tcpdump Download the hub.py module and copy it in the ~/pyretic/pyretic/examples directory: $ cd ~/pyretic/pyretic/examples $ wget https://d396qusza40orc.cloudfront.net/sdn/srcs/pyretic_hub.py [ 5 ]

Now, run the basic hub example: $ pyretic.py -v high pyretic.examples.pyretic_hub This tells Pyretic to enable verbose logging and to start the hub component. (TIP: start pyretic first for quicker hookup w/ mininet) The switches may take a little bit of time to connect. When an OpenFlow switch loses its connection to a controller, it will generally increase the period between which it attempts to contact the controller, up to a maximum of 15 seconds. Since the OpenFlow switch has not connected yet, this delay may be anything between 0 and 15 seconds. If this is too long to wait, the switch can be configured to wait no more than N seconds using the maxbackoff parameter. Alternately, you exit Mininet to remove the switch(es), start the controller, and then start Mininet to immediately connect. Wait until the application indicates that the OpenFlow switch has connected. When the switch connects, Pyretic will print something like this: OpenFlow switch 1 connected 20130721 13:19:11.276764 clear_all 20130721 13:19:11.278561 clear_all 20130721 13:19:11.280613 clear_all 20130721 13:19:11.281942 clear_all Now verify that hosts can ping each other, and that all hosts see the exact same traffic the behavior of a hub. To do this, we'll create xterms for each host and view the traffic in each. In the Mininet console, start up three xterms: mininet> xterm h1 h2 h3 Arrange each xterm so that they're all on the screen at once. This may require reducing the height to fit a cramped laptop screen. In the xterms for h2 and h3, run tcpdump, a utility to print the packets seen by a host: # tcpdump -XX -n -i h2-eth0 and respectively: # tcpdump -XX -n -i h3eth0 In the xterm for h1, send a ping: # ping -c1 10.0.0.2 [ 6 ]

The ping packets are now going up to the controller, which then floods them out all interfaces except the sending one. You should see identical ARP and ICMP packets corresponding to the ping in both xterms running tcpdump. This is how a hub works; it sends all packets to every port on the network. Now, see what happens when a nonexistent host doesn't reply. From h1 xterm: # ping -c1 10.0.0.5 You should see three unanswered ARP requests in the tcpdump xterms. If your code is off later, three unanswered ARP requests is a signal that you might be accidentally dropping packets. You can close the xterms now. Now, lets look at the hub code (You can see the reduction in the amount of code needed to implement hub in Pyretic as compared to POX): from pyretic.lib.corelib import * from pyretic.lib.std import * def act_like_hub(): """Implement hub like behavior send all packets to all ports on a network minimum spanning tree, except for the input port""" return flood() # Return the policy flood def main(): return act_like_hub() Table 1. hub application 1.4. Verify Switch behavior with tcpdump This time, let s verify that hosts can ping each other when the controller is behaving like a layer 2 learning switch. Kill the Pyretic runtime by pressing Ctrl-C in the window running the program. Download the switch module and copy it in the ~/pyretic/pyretic/examples directory: $ cd ~/pyretic/pyretic/examples $ wget https://d396qusza40orc.cloudfront.net/sdn/srcs/pyretic_switch.py Now, run the switch example: $ pyretic.py v high pyretic.examples.pyretic_switch [ 7 ]

Like before, we'll create xterms for each host and view the traffic in each. In the Mininet console, start up three xterms: mininet> xterm h1 h2 h3 Arrange each xterm so that they're all on the screen at once. This may require reducing the height of to fit a cramped laptop screen. In the xterms for h2 and h3, run tcpdump, a utility to print the packets seen by a host: # tcpdump -XX -n -i h2-eth0 and respectively: # tcpdump -XX -n -i h3-eth0 In the xterm for h1, send a ping: # ping -c1 10.0.0.2 Here, the switch examines each packet and learn the sourceport mapping. Thereafter, the source MAC address will be associated with the port. If the destination of the packet is already associated with some port, the packet will be sent to the given port, else it will be flooded on all ports of the switch. You can close the xterms now. [ 8 ]

Let s have a look at the pyretic_switch code: (it s pretty self explanatory) from pyretic.lib.corelib import * from pyretic.lib.std import * # The @dynamic decorator means that the function below will create a new dynamic # policy class with the name "act_like_switch" @dynamic def act_like_switch(self): """ Implement switch like behavior. """ # Set up the initial forwarding behavior for your mac learning switch to flood # all packets self.forward = flood() # Set up a query that will receive new incoming packets self.query = packets(limit=1,group_by=['srcmac','switch']) # Set the initial internal policy value (each dynamic policy has a member 'policy' # when this member is assigned, the dynamic policy updates itself) self.policy = self.forward + self.query # hint: '+' operator on policies is shorthand for parallel composition # Function to take each new packet pkt and update the forwarding policy # so subsequent incoming packets on this switch whose dstmac matches pkt's srcmac # (accessed like in a dictionary pkt['srcmac']) will be forwarded out pkt's inport # (pyretic packets are located, so this value is accessed just like srcmac # i.e., p['inport']) def learn_from_a_packet(pkt): # Set the forwarding policy self.forward = if_(match(dstmac=pkt['srcmac'], switch=pkt['switch']), fwd(pkt['inport']), self.policy) # hint use 'match', '&', 'if_', and 'fwd' # Update the policy self.policy = self.forward + self.query # hint you've already written this print self.policy # learn_from_a_packet is called back every time our query sees a new packet self.query.register_callback(learn_from_a_packet) def main(): return act_like_switch() Table 2. switch application [ 9 ]

1.4.1. Useful Pyretic policies match(f=v): filters only those packets whose header field f's value matches v ~A: negates a match A & B: logical intersection of matches A and B A B: logical union of matches A and B fwd(a): forward packet out port a flood(): send all packets to all ports on a network minimum spanning tree, except for the input port A >> B: A's output becomes B's input A + B: A's output and B's output are combined if_(m,a,b): if packet filtered by M, then use A, otherwise use B 1.5. Assignment 1.5.1. Background A firewall is a network security system that is used to control the flow of ingress and egress traffic usually between a more secure localarea network (LAN) and a less secure widearea network (WAN). The system analyses data packets for parameters like L2/L3 headers or performs deep packet inspection (DPI) for higher layer parameters (like application type and services etc) to filter network traffic. A firewall acts as a barricade between a trusted, secure internal network and another network (e.g. the Internet) which is supposed to be not very secure or trusted. In this assignment, your task is to implement a layer 2 firewall that runs alongside the MAC learning module on the Pyretic runtime. The firewall application is provided with a list of MAC address pairs i.e., access control list (ACLs). When a connection establishes between the controller and the switch, the application installs static flow rule entries in the OpenFlow table to disable all communication between each MAC pair. 1.5.2. Network Topology Your firewall should be agnostic of the underlying topology. It should take MAC pair list as input and install it on the switches in the network. To make things simple, we will implement a less intelligent approach and will install rules on all the switches in the network. [ 10 ]

1.5.3. Understanding the Code To start this exercise, copy/paste in the files, the two codes as follows (table 1-2): ################################################################################ # The Pyretic Project # # frenetic-lang.org/pyretic # # author: Joshua Reich (jreich@cs.princeton.edu) # ################################################################################ # Licensed to the Pyretic Project by one or more contributors. See the # # NOTICES file distributed with this work for additional information # # regarding copyright and ownership. The Pyretic Project licenses this # # file to you under the following license. # # # # Redistribution and use in source and binary forms, with or without # # modification, are permitted provided the following conditions are met: # # - Redistributions of source code must retain the above copyright # # notice, this list of conditions and the following disclaimer. # # - Redistributions in binary form must reproduce the above copyright # # notice, this list of conditions and the following disclaimer in # # the documentation or other materials provided with the distribution. # # - The names of the copyright holds and contributors may not be used to # # endorse or promote products derived from this work without specific # # prior written permission. # # # # Unless required by applicable law or agreed to in writing, software # # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # # LICENSE file distributed with this work for specific language governing # # permissions and limitations under the License. # ################################################################################ from pyretic.lib.corelib import * from pyretic.lib.std import * # insert the name of the module and policy you want to import from pyretic.examples.<...> import <...> policy_file = "%s/pyretic/pyretic/examples/firewall-policies.csv" % os.environ[ 'HOME' ] def main(): # Copy the code you used to read firewall-policies.csv last week [ 11 ]

# start with a policy that doesn't match any packets not_allowed = none # and add traffic that isn't allowed for <each pair of MAC address in firewall-policies.csv>: not_allowed = not_allowed + ( <traffic going in one direction> ) + ( <traffic going in the other direction> ) # express allowed traffic in terms of not_allowed - hint use '~' allowed = <...> # and only send allowed traffic to the mac learning (act_like_switch) logic return allowed >> act_like_switch() Table 2: pyretic_firewall.py, a sekleton class which you will update with the logic for installing firewall rules. id,mac_0,mac_1 1,00:00:00:00:00:02,00:00:00:00:00:04 2,00:00:00:00:00:03,00:00:00:00:00:05 3,00:00:00:00:00:04,00:00:00:00:00:06 4,00:00:00:00:00:05,00:00:00:00:00:07 Table 3: firewallpolicies.csv: a list of MAC pairs (i.e., policies) read as input by the firewall application. You don t have to do any modifications in firewallpolicies.csv. The pyretic_firewall.py is populated with a skeleton code. It consists of a main function and a global variable (policy_file) that holds the path of the firewallpolicies.csv file. Whenever a connection is established between the Pyretic controller and the OpenFlow switch the main functions gets executed. Your task is to read the policy file and update the main function. The function should install policies in the OpenFlow switch that drop packets whenever a matching src/dst MAC address (for any of the listed MAC pairs) enters the switch 1.5.4. Testing your Code Once you have your code, copy the pyretic_firewall.py in the ~/pyretic/pyretic/examples directory on your VM. Also in the same directory create the following file: $ cd ~/pyretic/pyretic/examples $ touch firewallpolicies.csv and copy the following lines in it: id,mac_0,mac_1 1,00:00:00:00:00:01,00:00:00:00:00:02 [ 12 ]

This will cause the firewall application to install a flow rule entry to disable all communication between host h1) and host (h2). Run Pyretic runtime: $ cd ~ $ pyretic.py pyretic.examples.pyretic_firewall & Now run mininet: $ sudo mn --topo single,3 --controller remote --mac In mininet try to ping host (h2) from host (h1): mininet> h1 ping -c1 h2 What do you see? If everything has been done and setup correctly then host (h1) should not be able to ping host (h2). Now try pinging host (h3) from host (h1): mininet> h1 ping -c1 h3 What do you see? Host (h1) is able to ping host (h3) as there is no flow rule entry installed in the network to disable the communication between them. Bibliography [1] Pyretic Documentation Official Web Site, available in http://frenetic-lang.org/pyretic/ [2] Python Offical Web Site, available in http://www.python.org/ [3] Python Programming, several material available in https://wiki.python.org/moin/pythonbooks [4] Introduction to Mininet, available in https://github.com/mininet/mininet/wiki/introduction-to-mininet [ 13 ]