convert kmeans_incr threshold
[actl.git] / app-l2_hub / l2_hub.c
bloba6529659367768607869c5eb07581a37238ecec2
1 /*
2 * Copyright (c) 2016 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 #include <libof.h>
18 #include <of10.h>
20 #include <net/if_arp.h>
21 #include <netinet/in.h>
22 #include <netinet/if_ether.h>
24 #include <actl.h>
26 #include <stdio.h>
27 #include <stdlib.h>
29 static struct actl_ctx *ctx;
31 int
32 init(struct actl_ctx *c)
34 ctx = c;
35 printf("l2_hub initialized.\n");
36 return 0;
39 int
40 main(int argc, char **argv)
42 printf("L2_hub ready.\n");
43 return 0;
46 void
47 handler(struct of_event *ev)
49 struct ether_header *eh;
50 struct of10_packet_in *ph;
51 struct of10_packet_out *msg_out;
52 struct of10_action_output *action;
54 if (ev->type != OFEV_PROTO_MESSAGE)
55 return;
57 ph = (struct of10_packet_in *)(ev->ofp_hdr);
58 eh = (struct ether_header *)(ph->data);
60 #ifdef DEBUG
61 printf("in_port: %hu, ", ntohs(ph->in_port));
62 printf("%x:%x:%x:%x:%x:%x ->", eh->ether_shost[0], eh->ether_shost[1],
63 eh->ether_shost[2], eh->ether_shost[3], eh->ether_shost[4],
64 eh->ether_shost[5]);
65 printf(" %x:%x:%x:%x:%x:%x, ", eh->ether_dhost[0], eh->ether_dhost[1],
66 eh->ether_dhost[2], eh->ether_dhost[3], eh->ether_dhost[4],
67 eh->ether_dhost[5]);
68 printf("type: 0x%hx ", ntohs(eh->ether_type));
69 if (ntohs(eh->ether_type) == ETHERTYPE_ARP)
70 printf("[ARP]");
71 else if (ntohs(eh->ether_type) == ETHERTYPE_IP)
72 printf("[IP4]");
73 printf("\n");
74 #endif
76 /* flood */
77 msg_out = (struct of10_packet_out *)malloc(sizeof(struct of10_packet_out) + sizeof(struct of10_action_output));
78 if (msg_out == NULL)
79 return;
80 msg_out->hdr.version = OFP_VERSION_10;
81 msg_out->hdr.type = OFPT10_PACKET_OUT;
82 msg_out->hdr.length = htons(sizeof(struct of10_packet_out) + sizeof(struct of10_action_output));
83 msg_out->hdr.xid = 0;
84 msg_out->buffer_id = ph->buffer_id;
85 msg_out->in_port = ph->in_port;
86 msg_out->actions_len = htons(sizeof(struct of10_action_output));
87 action = (struct of10_action_output *)(msg_out->actions);
88 action->type = htons(OFPAT10_OUTPUT);
89 action->len = htons(sizeof(struct of10_action_output));
90 action->port = htons(OFPP10_FLOOD);
91 action->max_len = 0;
92 ctx->cntl->send(ctx->cntl, ev->dp, (struct ofp_header *)msg_out);
93 free(msg_out);
96 double
97 kpi()
99 return 0;