fix a header guard
[libof.git] / libof.h
blob1d2aac35cb20baa11694d7d2a5b0ce73fc6d1a99
1 /*
2 * Copyright (c) 2015 Mohamed Aslan <maslan@sce.carleton.ca>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef LIBOF_H
18 #define LIBOF_H
20 #include <stdint.h>
21 #include <time.h>
22 #include <sys/socket.h>
24 #include <hashtab.h>
26 #define OFP_VERSION_10 0x01
28 enum of_event_type {
29 OFEV_CONNECTION_UP,
30 OFEV_CONNECTION_DOWN,
31 OFEV_PROTO_MESSAGE
34 struct of_event {
35 enum of_event_type type;
36 struct of_dataplane *dp;
37 union {
38 struct ofp_header *ofp_hdr;
42 struct of_dataplane {
43 int socket;
44 int ready;
45 struct sockaddr_storage sw_addr;
46 time_t lastmsg_ts;
47 const struct of_protocol *protocol;
48 struct ofp_header *sw_features;
51 struct of_controller {
52 int socket;
53 int port;
54 int ev_queue;
55 int n_timers;
56 struct hashtab conns; /* map: int -> uintptr_t, socket to struct dataplane* */
57 struct hashtab dpids; /* map: uint64_t -> uinptr_t, dpid to struct dataplane* */
58 struct hashtab timer_callbacks; /* timer call backs */
59 const struct of_protocol *protocol;
60 void (*of_handler)(struct of_controller *, struct of_event *);
62 void (*handler)(struct of_controller *, void (*)(struct of_controller *, struct of_event *));
63 void (*timer)(struct of_controller *, unsigned int, void (*)(struct of_controller *));
64 void (*send)(struct of_controller *, struct of_dataplane *, struct ofp_header *);
65 void (*loop)(struct of_controller *);
68 struct of_protocol {
69 uint8_t version;
70 void (*init)(struct of_controller *);
71 int (*handshake)(struct of_controller *, struct of_dataplane *); /* async handshake */
72 int (*recv)(struct of_controller *, struct of_dataplane *, struct ofp_header *);
73 int (*ping)(struct of_controller *, struct of_dataplane *); /* async ping */
77 assume that ofp_header will be the same across all OpenFlow versions
79 struct ofp_header {
80 uint8_t version;
81 uint8_t type;
82 uint16_t length;
83 uint32_t xid;
84 }__attribute__((packed));
85 /* assert(sizeof(struct ofp_header) == 8); */
88 int of_controller_init(struct of_controller *, int, const struct of_protocol *);
90 #endif