Rich Lane | a06d0c3 | 2013-03-25 08:52:03 -0700 | [diff] [blame] | 1 | Introduction |
| 2 | ============ |
| 3 | |
| 4 | LOCI is the C language module of LOXI, the Logical OpenFlow Extensible |
| 5 | Interface. It provides a framework for managing OpenFlow objects in |
| 6 | an object oriented fashion. |
| 7 | |
| 8 | All files in LOCI, even this README, are generated by LOXI. Please make |
| 9 | modifications to LOXI instead of to these files directly. |
| 10 | |
| 11 | Compilation |
| 12 | =========== |
| 13 | |
| 14 | It's expected that users of LOCI will want to integrate it into their own build |
| 15 | system. As an example, here's a simple command line to create a shared library |
| 16 | on Linux: |
| 17 | |
| 18 | gcc -fPIC -shared -I inc src/*.c -o loci.so |
| 19 | |
| 20 | LOCI has no dependencies beyond the C standard library. |
| 21 | |
| 22 | Documentation |
| 23 | ============= |
| 24 | |
| 25 | A Doxygen configuration file is provided. Just run `doxygen` to generate HTML |
| 26 | documentation pages. Each OpenFlow object is linked to under the "Modules" |
| 27 | tab. |
| 28 | |
| 29 | Usage |
| 30 | ===== |
| 31 | |
| 32 | Currently the best example code for using LOCI is the switchlight-core |
| 33 | repository. |
| 34 | |
| 35 | Here's example code that creates a flow mod: |
| 36 | |
| 37 | /* Create the match */ |
| 38 | of_match_t match; |
| 39 | memset(&match, 0, sizeof(match)); |
| 40 | match.fields.in_port = 1; |
| 41 | OF_MATCH_MASK_IN_PORT_EXACT_SET(&match); |
| 42 | match.fields.eth_type = 0x8000; |
| 43 | OF_MATCH_MASK_ETH_TYPE_EXACT_SET(&match); |
| 44 | |
| 45 | /* Create a flow mod */ |
| 46 | of_flow_add_t *flow_add = of_flow_add_new(OF_VERSION_1_0); |
| 47 | of_flow_add_idle_timeout_set(flow_add, 5); |
| 48 | of_flow_add_cookie_set(flow_add, 42); |
| 49 | of_flow_add_priority_set(flow_add, 10000); |
| 50 | of_flow_add_buffer_id_set(flow_add, -1); |
| 51 | if (of_flow_add_match_set(flow_add, &match)) { |
| 52 | fprintf(stderr, "Failed to set the match field\n"); |
| 53 | abort(); |
| 54 | } |
| 55 | |
| 56 | /* Populate the action list */ |
| 57 | of_list_action_t actions; |
| 58 | of_flow_add_actions_bind(flow_add, &actions); |
| 59 | int i; |
| 60 | for (i = 1; i <= 4; i++) { |
| 61 | of_action_output_t action; |
| 62 | of_action_output_init(&action, flow_add->version, -1, 1); |
| 63 | of_list_action_append_bind(&actions, (of_action_t *)&action); |
| 64 | of_action_output_port_set(&action, i); |
| 65 | } |
| 66 | |
| 67 | /* Use the underlying buffer */ |
| 68 | void *buf = WBUF_BUF(OF_OBJECT_TO_WBUF(flow_add)); |
| 69 | uint16_t len = flow_add->length; |
| 70 | /* ... */ |
| 71 | |
| 72 | /* Free the flow mod */ |
| 73 | of_flow_add_delete(flow_add); |