Download presentation
Presentation is loading. Please wait.
1
Trema: A Brief Introduction and Tutorial
TEIN3 Annual NOC Workshop Trema: A Brief Introduction and Tutorial Shuji Ishii National Institute of Information and Communications Technology Hi, my name is Shuji Ishii from NICT Japan. I am in charge of developing openflow controller for JGN-X openflow testbed. In this talk , I would like to introduce about Trema, a openflow controller software platform, briefly Before talking about trema, I will talk about brief introduction of OpenFlow. 11/08/26
2
Outline Introduction of OpenFlow Introduction of Trema
Brief tutorial (Hands-on) of Trema How to build Basic operations Advanced topics This is outline of today’s talk. There three parts in this presentation. First I will talk about brief intrduction of openflow. Then will talk about introduction and tutorial of trema. In the tutorial, I will explain ‘how to build’, and basic operations 11/08/26
3
Brief introduction of OpenFlow
So, I would like to introduce openflow briefly Brief introduction of OpenFlow 11/08/26
4
What is OpenFlow? From white-paper “OpenFlow is based on an Ethernet switch, with an internal flow-table, and a standardized interface to add and remove flow entries.” From white-paper, openflow is based on an ethernet switch, with an internal flow-table, and a standardized interface to add and remove flow entries. 11/08/26
5
Modern Ethernet Switch
Control Function Forwarding Engine This slide shows modern ethernet switches. They have control function and forwarding engine. Forwarding engine forwards receiving packets with flow table. Control function controls this forwarding engine and flow tables. For example, add red flow into flow table. Flow table 11/08/26
6
If you have an idea ... You have to modify “control function”
It is hard to modify production equipment PC-based? Yes, but performance is not enough. So, if you have an idea of new network technology and protocols, you have to modify “control function”. But, it is hard to modify production equipment. Yes, of cause, you can build and use PC-based switches / routers. However, its performance is limited 11/08/26
7
Basic idea of OpenFlow Separate Control function and Forwarding engine. OpenFlow Controller (OFC) OpenFlow Switch (OFS) Provide standard interface to control Forwarding engine. Control Function Forwarding Engine This figure explains basic idea of openflow. The idea is, separate control function and forwarding engine. They called ‘openflow controller(OFC)’ and ‘openflow switch(OFS)’ respectively. And it provides standard interface to forwarding engine. Flow table Forwarding Engine Forwarding Engine Flow table Flow table 11/08/26
8
Flow table It has three fields Match Instruction Statistics
Defines the flow Instruction Defines how the packets should be processed Statistics Match Instruction Statistics So, I would like to explain about flow table. Flow table is used to how to treat receiving packet when forwarding engine receives packets. Flow table has a lot of entries, and each entry has three fields. First field is a match field. This field specifies the flow. It can specify, input port, ethernet addresses, types, VLAN tags, MPLS headers, IP addresses, TCP/UDP port numbers and so on. Second is a instruction. This field specifies how to process the packet. For example, output to port, discard, modify fields, and so on. Last field is statistics. This field is a counter. Match Instruction Statistics Match Instruction Statistics 11/08/26
9
Match 10-tuples(OpenFlow 1.0)
Can specify wildcard (i.e. In_port = *, VLANID=33, …) Match Instruction Statistics This slide shows match field. It has 10 field. You can specify wildcard like this. In_port VLAN ID SA Type DA Ethernet SA Proto DA IP Src Dst TCP/UDP 11/08/26
10
Forwarding Control Function Found Forwarding Engine Found Flow table
This figure explains how to forward packets using flow-table. When packet arrives a port, forwarding engine looks up entry for this packet from flow table. If found, forwarding engine forwards the packet depending on matched entry. 11/08/26
11
Unknown packet Control Function Not found Packet In message
Flow table Forwarding Engine This figure explains how to treat unknown packets. Unknown means “not found in flow table” If not found, forwarding engine throws the event including the receiving packet to the controller. Then, controller will make some decisions, and may modify flow table. For example, add new entry, or just discard it. 11/08/26
12
Flow Mod Flow Mod Flow Table Flow Table Flow Table
This slide shows how the controller and switches work. Flow Table 11/08/26
13
? Packet Out Flow Mod Flow Mod Flow Table Flow Table Packet In
This is an another example. Flow Table 11/08/26
14
OpenFlow protocol Maintains flow tables in OFS
Create Delete Modify Notify unknown packet to OFC Gather information and statistics Miscellaneous commands Control Function Flow table This slide shows basic of openflow protocol. There are some groups of commands. First, maintaining flow tables in openflow switch, like creation, deletion, and modification. Second, notifying receiving unknown packet from openflow switch to openflow controller. Third, gathering information and statistics from switches. Last, miscellaneous commands, like hello, capability exchanges, and so on. 11/08/26
15
Who maintains the flow table?
Controller does! So, building your “network” is developing your own controller. This is a last slide of openflow introduction. Controller maintains flow table in openflow switches. So building your network is developing your own controller. 11/08/26
16
As I talked, building your own network into openflow network, you have to create your own openflow controller. In this part, I will talk how to create openflow controller with software platform trema. Introduction of Trema 11/08/26
17
Open Source OpenFlow Controller: Trema
A software platform for OpenFlow researchers and developers Not a production controller itself Multi-process modular architecture for extensibility Free software (GPLv2) Repository ML Integrated developing environment Seamless integration of controller and network environment for testing and debugging TDD (Test Driven Development) framework Trema is a software platform for developing openflow controller. For researchers and developers. It is not a production controller itself. It employs multi-process modular architecture for extensibility. It is free software distributed under GPLv2. this is a git repository and mail-list address. It has integrated developing environment. 11/08/26
18
Production environment
Background OpenFlow iceberg Scope of Trema Software development Trema is an OpenFlow platform for entire development process (like Rails) Shorter development cycle Reduce labor cost More and more research outputs :-) Debug Network setup Traffic generation Diagnose This slide shows scope of developing trema. Developing openflow controller needs a lot of debugs, setups, and so on. So, trema is an openflow platform for entire development process. Production environment 11/08/26 18
19
What is “Trema” Trema @ https://github.com/trema/trema
User OpenFlow controller Trema User module User module User module Core modules Shell Basic libraries OpenFlow protocol stack Debugger This figure shows trema’s architecture. Trema has several components. basic libraries, openflow protocol stack, core modules, shell and integrated network emulator environment. And user module(applications) are built on top of these components. Controller and network configuration OpenFlow Switch Integrated network emulator Host Real network Future scope 11/08/26
20
Integrated environment
Why integrated ? Network programming is essentially distributed programming OpenFlow controller State State State Mininet State State State OpenFlow controller State State State State This figure shows why integrated environment is needed. Because, network programming is distributed programming. It is not easy to implement some ideas under distributed environment. State State Mininet State Integrated environment State State State State State 11/08/26
21
A use case – automatic network slice creation from computing resource slice assignments
OpenStack ProtoGENI / PLC Quantum API Layer 2 shortest path routing (sample is provided) + virtual network slicing + access control + OSPF/BGP interwork + sophisticated path control and QoS many other research topics follow OpenFlow controller based on Trema Virtual network A This is a use case of openflow application. Automatic network slice creation from computing resource slice assignments. It has one openflow controller and some switches. Also external components like openstack, protoGENI/PLC, controll openflow controller to manage network slice. Virtual network B Virtual network C Server resource Pool 11/08/26 21
22
A use case – path management
Traffic engineering Multicast Stiching Address/tag translation + shortest path setup + traffic engineering + multicasting (P-to-MP path) etc. OpenFlow controller based on Trema This use case explains path management system using openflow. 11/08/26 22
23
Documents Web: Wiki: Manuals Install: Quick start: C API: not available now (3Q/2011 release) Ruby API: (Q3/2011) Tutorial This slide shows some documents list about trema. 11/08/26 23
24
Current status and work items
Core functions Core modules Switch manager, switch daemon, packet_in filter, etc… OpenFlow application interface (OpenFlow compliant) C APIs (fully compliant with the specification) Ruby bindings (work in progress. planned to be fully supported by Q3/2011) Libraries Basic data structures, packet parser, logging, hash table, linked list, timer, etc… Messenger Point-to-point messaging among processes Group messaging among hosts [T.B.D.] This is a current status and work items. Core functions…. 11/08/26 24
25
Current status and work items –cont’d
Development and test Test driven development framework (Ruby RSpec) [Q3/2011] Automated test environment [available and increasing coverage] automatic build, unit test, acceptance test, etc… Test and operation Network DSL and shell [available but updated frequently] Describe and manage network and controller configurations Module manager [T.B.D] Debug TremaShark Network debugger [planned] Network emulator Pseudo host [available and more functions planned] Virtual switch [available and more functions planned] 11/08/26 25
26
Roadmap Q3/2011 : Ruby support fully available
Q1/2012 : Full set of develop environment available Q3/2011 Q4/2011 Q1/2012 Complete Ruby support New messenger Module manager and operation support Network debugger and network emulator update 11/08/26 26
27
A bit more internal structure
Following a few slides explain some internal structure of trema. 11/08/26
28
Architecture overview
OpenFlow controller Script file Shell Trema DSL interpreter Module/object creation, configuration, and management Core module Core module User module User module User module vSwitch vHost OpenFlow, etc… Emulation network / physical network Messenger is a core function of trema. It is a IPC-system of trema. Trema components communicate each others with this messenger sub-system. Trema DSL interpreter is used for describing test/emulated environment. Emulated networks is implemented using openvswitch and homebrew trivial host function. Switch Host Messenger Logging / snapshot Logging / snapshot Network debugger / TremaShark 11/08/26 28
29
Development and operation
Multi-process model Functional modules loosely coupled via messenger User modules, core modules = process Messenger = messaging among modules on different processes/hosts Protecting a controller from someone installing unstable modules... Dynamically changing code (without having to stop) in the controller User modules Development and operation Discovery Topology Routing_ switch Debugging This slide shows trema’s implementation model. Each component is implemented as single UNIX process, and they are loosely coupled via messenger. In this figure, these components are core modules, these components are use moduels, debugging facilities, and development and operation functions. Trema DSL Trema Shark RPC monitoring Messenger Trema shell Network debugger Switch manager Switch Packet in filter 11/08/26 Core modules 29
30
Multi-process model – example
trema/src/examples/routing_switch Configuration file - Starting-up application processes - Module configurations (filters) - [Configure message routing (if not specified, use default service name)] Routing_ switch Topology request / reply Topology Link discovery app { path "./objects/examples/topology/topology" } path "./objects/examples/topology/topology_discovery" path "./objects/examples/routing_switch/routing_switch" event :port_status => "topology", packet_in => "filter", :state_notify => "topology" filter :lldp => "topology_discovery", :packet_in => “routing_switch" Other packet_in Switch info LLDP Packet in filter This slide explains example components’ structures. Switch listener Switch manager Switch 11/08/26 30
31
Messenger Messaging among modules on different processes/hosts
Messenger API SEND: send_message(service_name, tag, data, data_length) RECEIVE: add_message_received_callback(service_name, call_back_function) User module User module User module API API Messenger Messenger Messenger Service name This slide shows messenger architecture. Messenger’s functions is Messaging among components on different processes/hosts. These are messenger APIs (they are quite simple) Send, receive, Unix domain socket Point-to-point messaging within a host (current) Pub-sub messaging among multiple hosts (planned) 11/08/26 31
32
Language support User modules can be written in C or Ruby
Provides C libraries and Ruby bindings Advantages to use Ruby Easy to write Integrated with test framework (sophisticated tests using built-in network emulator) But maybe slower than C… Mixture of C and Ruby modules Faster modules in C and slower modules in Ruby Prototype and test in Ruby first, then rewrite to C This slide explains trema’s language support. Now, user modules can be written in C or ruby Advantage to use ruby…. 11/08/26 32
33
Internal APIs OpenFlow 1.0.0 (C and Ruby) Basic libraries (C and Ruby)
packet parser*1, logging, hash table*2, linked list*2, timer, etc. Messenger (C and Ruby*1) *1 ruby in progress *2 use Ruby built-in User module APIs Ruby bindings This slide shows internal APIs of trema. OpenFlow Basic libraries Messenger Switches 11/08/26 33
34
Configurations and external interfaces
Command line options Configurations described in configuration file are passed to each module as command line options Configurations CLI, REST External interfaces REST Persistent database SQLite No official framework is provided yet This slide explains how to configure and manage trema. Now, There is just one interface: command line options. We have plan to implement these frameworks in the future. 11/08/26 34
35
Configurations and external interfaces - example
L2+ routing switch CLI REST L2+_routing_switch Port and MAC-based L2 network slicing L1-4 access control list (ACL) apache parser cgi Config mgmt. SQLite library SQLite library Configuration database Slice configuration ACL configuration 11/08/26 35
36
Development, test and debug [work-in-progress]
TDD (Test Driven Development) Specification (test scenario) and implementation are integrated allows frequent implementation changes Test scenario involves both controller and network, thus, their configurations and operations are integrated (network DSL) Integrated network debugger Ruby C Development framework Programming in Ruby Programming in C Network DSL & Shell - controller description - network description Object manipulation Test driven development (Ruby only) Integrated network debugger This shows development, test and debug framework, but is work-in-progress Controller setup (module integration) TremaShark -Visualize internal messaging Network debugger -Visualize and trace events through network and controller Test on emulated network Test on real network Enjoy 11/08/26 36
37
TremaShark Wireshark plug-in for monitoring any IPC events among/on functional modules Messages Secure Channel status Queue status etc… Event capture Learning switch Switch manager Switch This figure shows tremashark, a wireshark plug-in for monitoring any IPC events among/on functional modules. Functional modules 11/08/26 37
38
Directories features/ #test code spec/ #test code utilities/ #test code src/ examples/ #sample code libs/ #C libraries tremashark/ #tremashark vender/ #3rd part software (OVS, oflops, etc.) ruby/ #Ruby bindings built.rb #Trema build script cruse.rb #CI script for developers trema #Trema command They are directory lists of trema distribution package. 11/08/26 38
39
Trema applications as of Sep. 2011
Sample applications hello_trema, openflow_message, packet_In, switch_Info, switch_monitor (C, Ruby) dumper (C, Ruby) list_switches (C) repeater_hub (C, Ruby) cbench_switch (C) 3rd party redirectable_routing_switch (C) learning_switch / multi_learning_switch (C, Ruby) routing_switch (C) topology, discovery (C) : This slide shows current status of trema applications. 11/08/26 39
40
Conclusion Trema is a software platform for OpenFlow researchers and developers Multi-process modular architecture for extensibility Integrated developing environment TDD (Test Driven Development) framework Seamless integration of controller and emulated network for testing/debugging User modules written in C or Ruby Contact: 11/08/26 40
41
Backup 11/08/26
42
External (northbound) APIs
Trema itself does not specify external APIs, but applications do OpenStack VN mgmt. (Quantum-API) Plug-in L4 ACL Router configuration VN mgmt. (L2 slice) REST-API l2plus_routing_switch -MAC-based L2 network slice -L4 ACL simple_router -Logical router instance (forwarding plane) -FIB -ARP, ICMP, etc... Bgpd -RIB Trema 11/08/26 42
43
A use case – collaboration on a controller
Protecting a controller from someone installing unstable modules... Isolate modules as independent processes Dynamically changing code (without having to stop/start) in the controller Independently restarted App. A App. B App. C Module manager Topology management Users Core modules Administrator T.B.D. Switch 11/08/26 43
44
Trema Basic Operations
So, I would like to introduce openflow briefly Trema Basic Operations 11/08/26
45
Objectives and agenda Objectives Agenda
Learn how to build and run Trema and its sample applications Learn how to configure the integrated network emulator and applications Learn how to use ‘trema’ command which allows you to interact with Trema, its application, and network emulator Agenda How to obtain and build Trema How to run Trema applications Configuring network emulator and applications ‘trema’ command overview There are 4 lessons (demos) – Please join the lessons if you have your own Linux environment So, let’s start the tutorial. Objectives of this tutorial are learn... and how to and finally learn how to.. Agenda corresponds to the objectives. In this tutorial, there are 4 lessons, I mean demos. If you have your own Linux environment, please follow lessons with me. 11/08/26
46
How to obtain and build Trema: Before you begin…
Of course we need a build and run environment ! Ubuntu (i386/amd64) Ubuntu (i386/amd64) Ubuntu – LTS (i386/amd64) Debian GNU/Linux 6.0 (i386/amd64) May also work on other modern/latest Linux operating systems with Linux , GCC 4.3+, and Ruby 1.8.7 CentOS 5.x is definitely NOT supported due to very old Linux kernel and GCC Please make sure you are connected to the Internet ! Before start to explain how to build and operate Trema, I would like to clarify supported environment. We support the following operating systems. Since we have an automated build and test environment for these environment, they are always tested daily. Of course, Trema may run with the modern and latest Linux distributions, but they are not tested yet. This is FAQ but CentOS 5.x is definitely not supported due to very old software versions. In the lessons of this tutorial, we require Internet connection to obtain Trema and required packages. So please make sure that you are connected to the Internet if you join the lessons. 11/08/26
47
How to obtain and build Trema: It’s time to get and build
Make sure that all necessary software packages are installed: $ sudo apt-get install git gcc make ruby ruby-dev rubygems libpcap-dev Get Trema from github: $ git clone git://github.com/trema/trema.git There is no release version at this moment. We suggest you to get the latest version. So let’s obtain and build trema. It’s very easy! Please install required packages as shown here and then just clone source code tree from github. There is NO complicated dependencies. Since there is not release versions at this moment and code is changing, we suggest you to obtain the latest code tree. To build Trema and sample applications, just run build.rb as shown here. It takes only a few minutes to build. Build Trema and sample applications: $ cd trema $ ./build.rb That’s It! 11/08/26
48
Lesson 1 : Let’s build ! $ sudo apt-get install git-core gcc make ruby ruby-dev rubygems libpcap-dev libsqlite3-dev $ git clone git://github.com/trema/trema.git $ cd trema $ ./build.rb So let’s do a lesson. Please try to build Trema and sample applications on your environment. Let me try to do with my clean Ubuntu environment. I just installed Ubuntu this morning and installed only one additional package, openssh server, for this demo. As you could see, it is very easy to build Trema and its samples. 11/08/26
49
How to run Trema applications: Sample applications
Sample applications found in trema/src/examples: Dumper : OpenFlow event dumper Repeater Hub : Repeater Hub emulation Learning Switch : Learning switch emulation with a single OpenFlow Switch Multi Learning Switch: Learning switches emulation with multiple OpenFlow switches support etc. Most of samples have both C and Ruby version code with the same functionality I would like to quickly explain about sample applications. You can find them in trema/src/examples and there are several samples. There are dumper which .. , repeater hub which .., learning switch which .., multi learning switch which .., etc. Most of samples have both C and Ruby version code with the same functionality. I don’t explain each sample in detail in this tutorial but please take a look if you are interested in. They should help your controller application development. 11/08/26
50
How to run Trema applications: It’s time to run !
Application executable (binary or ruby script) Run Dumper with a configuration file $ ./trema run ./objects/examples/dumper/dumper -c ./src/examples/dumper/dumper.conf Configuration file Now you can see any OpenFlow events [switch_ready] datapath_id: 0xabc [features_reply] transaction_id: 0x660c0001 n_buffers: 256 n_tables: 2 capabilities: 0x87 actions: 0x7ff port_no: 65534 hw_addr: da:ad:cd:76:d8:3f name: vsw_0xabc … Next step is how to run application. Trema privide a command named ‘trema’ to manage application and integrated network emulator. To run an application, ‘trema’ command takes four arguments. ‘run’ means ‘start an application and an emulated network’. The second argument specifies an application to be executed. This argument can be binary, C language based application, or Ruby script. ‘-c’ means ‘take a configuration file’. For the configuration, I will explain later. The last argument is configuration file to be loaded. If you run this command, you will be able to see OpenFlow related events on your console terminal. 11/08/26
51
How to run Trema applications: It’s time to terminate !
Just type Ctrl-C to terminate running application $ ./trema run ./objects/examples/dumper/dumper -c ./src/examples/dumper/dumper.conf ^C terminated So the next question may be how to terminate running application. Please just type Ctrl-C to terminate the application. 11/08/26
52
How to run Trema applications: Run in background?
Just add ‘-d’ option $ ./trema run ./objects/examples/dumper/dumper -c ./src/examples/dumper/dumper.conf –d ‘trema killall’ to terminate daemonized application $ ./trema killall When you want to run application in background. You just need to add ‘-d’ option to the trema command. If you are running application in background, ‘trema killall’ allows you to terminate the application. 11/08/26
53
How to run Trema applications: Other sample apps?
Repeater Hub $ ./trema run ./objects/examples/repeater_hub/repeater_hub -c ./src/examples/repeater_hub/repeater_hub.conf Learning Switch $ ./trema run ./objects/examples/learning_switch/learning_switch -c ./src/examples/learning_switch/learning_switch.conf Multi Learning Switch For other samples, it’s the same as previous slides. $ ./trema run ./objects/examples/multi_learning_switch/multi_learning_switch -c ./src/examples/multi_learning_switch/multi_learning_switch.conf 11/08/26
54
How to run Trema applications: Run w/o network emu?
Don’t worry. Just run without configuration file ! $ ./trema run ./objects/examples/dumper/dumper Now Trema accepts secure channel connections from any OpenFlow switches without network emulator It is not possible to allow connections only from authorized switches at this moment. But still application can ignore any events from unauthorized (unknown) switches. Even if you have an emulator configuration in configuration file, secure channel connections are accepted. As I said, a configuration file includes a configuration for the integrated network emulator. When you want to connect real OpenFlow switches, just remove configuration file part from ‘trema’ command. For details of configuration file will be explained later. Detailed configuration file structure is explained later. 11/08/26
55
How to run Trema applications: Need to debug?
Set LOGGING_LEVEL environment variable to change log level $ LOGGING_LEVEL=debug ./trema run ./objects/examples/dumper/dumper critical, error, warn, notice, info, or debug is allowed to set. info is default. Log files found in trema/tmp/log Sending SIGUSR1 to applications output statistics collected by Trema to stdout or log files (if daemonized) So the next question may be how to debug or see log files. There is an environment variable, LOGGING_LEVEL, to set log level. ‘info’ is set by default but you can change it to other options if you like. For example, if you set it to ‘debug’ like this all log messages are generated. The log files are located in trema/tmp/log. And this is an advanced usage of Trema, if you send a SIGUSR1 to application, then you will get statistics. $ kill –USR1 `cat tmp/dumper.pid` 11/08/26
56
Lesson 2 : Let’s run dumper sample
$ ./trema run ./objects/examples/dumper/dumper –c ./src/examples/dumper/dumper.conf ^C $ ./trema run ./objects/examples/dumper/dumper –c ./src/examples/dumper/dumper.conf –d $ cat tmp/log/dumper.log $ ./trema killall So.. It’s time to lesson. Please try to run and terminate a sample application, dumper. Let me try... 11/08/26
57
Configuring network emulator and applications
In configuration file, you can configure Integrated OpenFlow network emulator Applications on top of Trema No configuration cause default behaviors No network emulator configuration – no network emulator No applications configuration – an application must be specified as an argument of ‘trema’ command Next topic is configuration. In the configuration file, you can configure.. It is important to understand that ‘no configuration’ provides default behavior. No network emulator configuration means no network emulator. No application configuration means application is specified with ‘trema’ command. 11/08/26
58
Configuring network emulator and applications
vswitch("dumper") { datapath_id "0xabc" } vhost("host1") vhost("host2") link "dumper", "host1" link "dumper", "host2" dumper.conf defines emulated network environment dumper ( 0xabc ) host1 host2 You can assign any human-readable name to switch / host. Let’s look into dumper.conf in trema/examples/dumper as an example. There is a network emulator configuration like this. You can simply specify OpenFlow switch, hosts, and links. You can specify names of elements that can be referenced by ‘trema’ command. It looks like something wrong since there are default values to be taken. MAC and IP addresses are automatically assigned if you omit them. How to interact with emulated network is introduced later. 11/08/26
59
Configuring network emulator and applications
Want to specify addresses? vswitch("dumper") { datapath_id "0xabc" } vhost("host1") { ip " " netmask " " mac "00:00:00:01:00:01" } vhost("host2") { ip " " mac "00:00:00:01:00:02" link "dumper", "host1" link "dumper", "host2" Of course, we can specify addresses like this. 11/08/26
60
Configuring network emulator and applications
Want to have more switches and hosts? vswitch("switch1") { datapath_id "0x1" } vswitch("switch2") { datapath_id "0x2" } vswitch("switch3") { datapath_id "0x3" } vhost("host1") vhost("host2") vhost("host3") link "switch1", "host1" link "switch2", "host2" link "switch3", "host3" link "switch1", "switch2" link "switch2", "switch3" host1 switch1 ( 0x1 ) host2 host3 switch2 ( 0x2 ) switch3 ( 0x3 ) If you need more switches and hosts. It looks like this. 11/08/26
61
Configuring network emulator and applications
Defining an application in configuration file? vswitch("dumper") { datapath_id "0xabc" } vhost("host1") vhost("host2") link "dumper", "host1" link "dumper", "host2" app { path "./objects/examples/dumper/dumper" } This slice show how to configure application. An application is specified as an argument of ‘trema’ command but it can also be defined in configuration file like this. If you specify an application, the you can run ‘trema’ command only with a configuration file. Now you can simply run an application with a configuration file: $ ./trema run -c ./src/examples/dumper/dumper.conf 11/08/26
62
Lesson 3 : Let’s create your emulated network
switch1 ( 0x1 ) switch2 ( 0x2 ) switch3 ( 0x3 ) switch4 ( 0x4 ) host1 host2 It’s time to lesson again. So let’s create this kind of emulated network. The answer might be 11/08/26
63
Lesson 3 : Let’s create an emulated network
vswitch("switch1") { datapath_id "0x1" } vswitch("switch2") { datapath_id "0x2" } vswitch("switch3") { datapath_id "0x3" } vswitch("switch3") { datapath_id "0x4" } vhost("host1") vhost("host2") link "switch1", "switch2" link "switch1", "switch3" link "switch2", "switch4" link "switch3", "switch4" link "switch3", "host1" link "switch4", "host2" 11/08/26
64
‘trema’ command overview
‘trema’ command allows you to run and terminate application developed on top of Trema (as you saw) It also allows you to interact with emulated network (i.e. switches and hosts) $ ./trema help usage: ./trema <COMMAND> [OPTIONS ...] Trema command-line tool Type './trema help <COMMAND>' for help on a specific command. Available commands: run runs a trema application. killall terminates all trema processes. send_packets - sends UDP packets to destination host. show_stats shows stats of packets. reset_stats - resets stats of packets. dump_flows print all flow entries. Now I would like to explain ‘trema’ command in detail. As you could see, ‘trema’ command allows you to run and terminate application on top of Trema. ‘trema’ command also allows you to interact with emulated network. There are only a few functions at this moment but it may be useful. ‘trema’ command allows you to send packets from a host, show and reset packet counters on hosts, show flow entries on switches. Already explained 11/08/26
65
‘trema’ command overview: send packets
Send UDP packets from a host to another $ ./trema send_packets --source host1 --dest host2 Only one UDP packet is sent out by default. Send 1000 packets with specified port number for 10 seconds $ ./trema send_packets --source host1 --dest host2 --pps duration 10 --tp_src tp_dst 5678 If you want to send a packet from a host to another. Just type as this. In this case, only a single UDP packet is sent with default parameters I mean port numbers. If you want to send a number of packets, then you can use n_pkts option. And also you can specify port numbers or sending duration like this. If you want to create multiple flows, then you can use increment option like inc_tp_src can be used. Send packets with incrementing source port number from 0 $ ./trema send_packets --source host1 --dest host2 --duration 10 --tp_src 0 --inc_tp_src Port number is wraparound if it overflows. 11/08/26
66
‘trema’ command overview: send packets – more options
Full options description $ ./trema help send_packets Usage: ./trema send_packets [OPTIONS ...] -s, --source HOSTNAME --inc_ip_src [NUMBER] -d, --dest HOSTNAME --inc_ip_dst [NUMBER] --tp_src NUMBER --inc_tp_src [NUMBER] --tp_dst NUMBER --inc_tp_dst [NUMBER] --pps NUMBER --n_pkts NUMBER --duration NUMBER --length NUMBER --inc_payload [NUMBER] -h, --help -v, --verbose This is the full description of send_packet sub command. 11/08/26
67
‘trema’ command overview: show stats and reset stats
Show TX/RX packet counters on a host $ ./trema show_stats host1 --tx $ ./trema show_stats host1 --rx Full options description $ ./trema help show_stats Usage: ./trema show_stats [OPTIONS ...] -t, --tx -r, --rx -h, --help -v, --verbose After sending packets, you can see packet counters on hosts as this. If you reset the counter, just run reset_stats sub command to do it. Reset (clear) packet counters on a host $ ./trema reset_stats host1 11/08/26
68
‘trema’ command overview: dump flows
Show flow entries registered on a switch $ ./trema dump_flows dumper 11/08/26
69
Lesson 4 : Run learning switch and confirm its behavior
Run learning switch sample application with two hosts (host1 and host2) and a single switch (lsw) Send a packet from a host (host1) to another (host2) Confirm that the packet is received on the destination host (host2) Confirm that no flow entry is created Send a packet from a host (host2) to another (host1) Confirm that the packet is received on the destination host (host1) and a flow entries is registered on the switch So, this is the last lesson. Let’s try to run learning switch sample and test if it works fine or not. The test scenario might be this list. 11/08/26
70
Lesson 4 : Run learning switch and confirm its behavior
$ ./trema run ./objects/examples/learning_switch/learning_switch -c ./src/examples/learning_switch/learning_switch.conf -d $ ./trema send_packets --source host1 --dest host2 $ ./trema show_stats host2 --rx ip_dst,tp_dst,ip_src,tp_src,n_pkts,n_octets ,1, ,1,1,50 $ ./trema dump_flows lsw Jul 24 17:51:01|00001|ofctl|INFO|connecting to unix:/home/y-chiba/trema/tmp/vsw_0xabc.mgmt stats_reply (xid=0xc3d5ecea): flags=none type=1(flow) $ ./trema send_packets --source host2 --dest host1 $ ./trema show_stats host1 --rx ,1, ,1,1,50 Jul 24 17:51:13|00001|ofctl|INFO|connecting to unix:/home/y-chiba/trema/tmp/vsw_0xabc.mgmt stats_reply (xid=0xffa1cd04): flags=none type=1(flow) cookie=0x1, duration_sec=7s, duration_nsec= ns, table_id=1, priority=65535, n_packets=1, n_bytes=64, idle_timeout=60,udp,in_port=2,dl_vlan=65535,dl_vlan_pcp=0,dl_src=00:00:00:01:00:02,dl_dst=00:00:00:01:00:01,nw_src= ,nw_dst= ,tp_src=1,tp_dst=1,actions=output:1 Lesson 4 : Run learning switch and confirm its behavior This is the answer and results. You can confirm packets are sent successfully and a flow entry is created properly. 11/08/26
71
Not explained in this tutorial though…
More Advanced Topics Not explained in this tutorial though… Here are some more advanced topics but due to time limitation, I do not explain them at this time. If you are interested in, take a look follows. 11/08/26
72
Configuring multiple applications?
You have multiple applications that handles different asynchronous events? app { path "./somewhere/app1" } path "./somewhere/app2" event :port_status => "app1", :packet_in => "app2", :state_notify => "app1" Trema specific events (switch connected/disconnected) Trema-provided event distribution might be still not flexible enough. Please let us know if you have any specific requirements on event distribution. Reply messages and Flow Removed messages are routed based on transaction ids or flow cookie values. 11/08/26
73
Interact with virtual switches directly?
Trema uses unmodified Open vSwitch as a virtual switch for the integrated network emulator Thus you can interact with the switches with command line tools (i.e. ovs-ofctl) provided by Open vSwitch ‘trema’ creates ovs-openflowd instances with vsw_datapath_id_in_hex (e.g. vsw_0xabc) ovs-ofctl show vsw_0xabc 11/08/26
74
Look into internals? Tremashark allows to visualize IPC events when you need to inspect IPC events among/on Trema core modules and applications How to use it? Build and install wireshark plugin (packet-trema.so) Run trema application with ‘use_tremashark’ option (in configuration file) Send SIGUSR2 to processes to be monitored $ kill –USR2 `cat tmp/dumper.pid` See trema/src/tremashark/README for details 11/08/26
75
Want to run with network namespace or mininet?
Trema’s network emulator creates virtual Ethernet devices (veth) which connect between switches and hosts. The devices are named as trema-X-Y You can attach trema-X-Y. to the namespaces with “ip link set trema-X-Y netns PID” as usual 11/08/26
76
Want to more interactively play with the Trema world?
Just run ‘trema’ command without any arguments ! Then you can enter to the Trema Shell that is based on irb (Interactive Ruby) 11/08/26
77
How to hack trema 11/08/26
78
Trivial load balancer Goal: Implement trivial load balancer using learning switch. 11/08/26
79
Basic flow of learning_switch
Initialize trema int main( int argc, char *argv[] ) { init_trema( &argc, &argv ); hash_table *forwarding_db = create_hash( compare_forwarding_entry, hash_forwarding_entry ); add_periodic_event_callback( AGING_INTERVAL, update_forwarding_db, forwarding_db ); set_packet_in_handler( handle_packet_in, forwarding_db ); start_trema(); return 0; } Set periodic callback Set packet_in event handler callback Main loop 11/08/26
80
Packet In handler Received packet object Learn receiving port
static void handle_packet_in( packet_in packet_in ) { struct key new_key; memcpy( new_key.mac, packet_info( packet_in.data )->l2_data.eth->macsa, OFP_ET H_ALEN ); new_key.datapath_id = packet_in.datapath_id; hash_table *forwarding_db = packet_in.user_data; learn( forwarding_db, new_key, packet_in.in_port ); struct key search_key; memcpy( search_key.mac, packet_info( packet_in.data )->l2_data.eth->macda, OFP _ETH_ALEN ); search_key.datapath_id = packet_in.datapath_id; forwarding_entry *destination = lookup_hash_entry( forwarding_db, &search_key ); if ( destination == NULL ) { do_flooding( packet_in ); } else { send_packet( destination->port_no, packet_in ); Received packet object Learn receiving port (src mac addr, port) Lookup destination port from dst mac address Flood if no destination ports found. Send packet to specified port. 11/08/26
81
How to hack? For simplify, server addresses and ports, client address and port are hard-coded. Specification: Test traffics are UDP Because trema send_packet subcommand cannot send TCP packet. Servers have same IP address. Determine output port by UDP source port. 11/08/26
82
Trivial load balancer Addresses 10.0.0.10/24 10.0.0.11/24 10.0.0.1/24
11/08/26
83
How to check? Use trema show_stats sub-command. 11/08/26
84
11/08/26
85
Thank you Trema web sites Web: http://trema.github.com/trema/
Wiki: Thank you for your kind attentions, if you are interested in trema, please visit these web sites. 11/08/26
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.