-//#include "admtest.h"
-#include "fwp_mngt.h"
-#include "fwp_contract_table.h"
-#include "fwp_agent_table.h"
+/**************************************************************************/
+/* ---------------------------------------------------------------------- */
+/* Copyright (C) 2006 - 2008 FRESCOR consortium partners: */
+/* */
+/* Universidad de Cantabria, SPAIN */
+/* University of York, UK */
+/* Scuola Superiore Sant'Anna, ITALY */
+/* Kaiserslautern University, GERMANY */
+/* Univ. Politécnica Valencia, SPAIN */
+/* Czech Technical University in Prague, CZECH REPUBLIC */
+/* ENEA SWEDEN */
+/* Thales Communication S.A. FRANCE */
+/* Visual Tools S.A. SPAIN */
+/* Rapita Systems Ltd UK */
+/* Evidence ITALY */
+/* */
+/* See http://www.frescor.org for a link to partners' websites */
+/* */
+/* FRESCOR project (FP6/2005/IST/5-034026) is funded */
+/* in part by the European Union Sixth Framework Programme */
+/* The European Union is not liable of any use that may be */
+/* made of this code. */
+/* */
+/* */
+/* This file is part of FWP (Frescor WLAN Protocol) */
+/* */
+/* FWP is free software; you can redistribute it and/or modify it */
+/* under terms of the GNU General Public License as published by the */
+/* Free Software Foundation; either version 2, or (at your option) any */
+/* later version. FWP is distributed in the hope that it will be */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* General Public License for more details. You should have received a */
+/* copy of the GNU General Public License along with FWP; see file */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, */
+/* Cambridge, MA 02139, USA. */
+/* */
+/* As a special exception, including FWP header files in a file, */
+/* instantiating FWP generics or templates, or linking other files */
+/* with FWP objects to produce an executable application, does not */
+/* by itself cause the resulting executable application to be covered */
+/* by the GNU General Public License. This exception does not */
+/* however invalidate any other reasons why the executable file might be */
+/* covered by the GNU Public License. */
+/**************************************************************************/
+#include <frm_generic.h>
+#include <forb.h>
+#include <error.h>
+#include <errno.h>
+#include <getopt.h>
+#include <fres_sa_scenario.h>
+#include <stdbool.h>
+#include <ul_log.h>
+#include <ul_logreg.h>
+#include <fwp_res.h>
+#include <stdio.h>
#include "fwp_admctrl.h"
-//static struct sockaddr_un fwp_laddr; /**< FWP local address */
-static struct sockaddr_in fwp_raddr; /**< FWP remote address */
-static int fwp_lsockfd; /**< FWP local sockfd */
-static int fwp_rsockfd; /**< FWP remote sockfd */
-static fd_set fwp_input_fdset;
-
-/* buffer and socket for incomming message */
-static unsigned char buffer[FWP_MTU];
-struct fwp_sockaddr peer;
+#if 0
+static
+int dummy_admission_test(struct fres_sa_scenario *scenario, void *priv,
+ bool *schedulable)
+{
+ struct fres_sa_contract *c;
-/* service vres */
-struct fwp_vres_params service_vparams;
-fwp_vres_d_t service_vresd; /**< service vres decriptor */
+ printf("Dummy admission test:\n");
-/* List of requested contracts */
-/*fwp_contractlist_t contractlist_req;*/
-/* for simplicity only one contract is to be negotiated now*/
-fwp_contract_data_t *contract_req;
+ fres_sa_scenario_for_each_no_cancel_contract(scenario, c) {
+ fres_block_basic *basic;
+ char id[40];
+ fres_contract_id_to_string(id, &c->contract->id, sizeof(id));
+ basic = fres_contract_get_basic(c->contract);
-/* Admission control test */
-fwp_admctrl_test_t fwp_admctrl_test = &fwp_admctrl_stupid;
+ printf(" processing: id=%s, period=%ld ms, budget=%ld ms\n",
+ id,
+ fosa_rel_time_to_msec(basic->period),
+ fosa_rel_time_to_msec(basic->budget));
-/**
- * fwp_agent_init
- *
- * FWP agent inicialization
- * - opens unix socket for local communication
- * - opens udp socket for remote comunication
- *
- * @fwp_mnr_addr_s string that contains the address of AP where
- * where fwp manager is located
- *
- */
-int fwp_mngr_init()
-{
- #if 0
- if ((fwp_lsockfd = fwp_create_unix_socket(FWP_AGENT_UNIXPATH,
- &fwp_laddr)) < 0) {
- return (fwp_lsockfd);
- }
- #endif
- if ((fwp_rsockfd = fwp_create_inet_socket(FWP_MNGR_UDP_PORT,
- &fwp_raddr)) < 0) {
- return (fwp_rsockfd);
}
+ *schedulable = scenario->num_contracts <= 3;
+ printf("=> %s\n", schedulable?"schedulable":"not schedulable");
- FD_ZERO(&fwp_input_fdset);
- //FD_SET(fwp_lsockfd, &fwp_input_fdset);
- FD_SET(fwp_rsockfd, &fwp_input_fdset);
-
- FWP_DEBUG("Manager initialized \n");
-
- /* create service vres */
- service_vparams.ac_id = FWP_AC_BK;
- service_vparams.budget = 100;
- service_vparams.period_usec = 1000;
-
- if ((fwp_vres_create(&service_vparams, &service_vresd) < 0)) {
- fprintf(stderr,"Unable to open service vres\n");
- return -1;
- }
-
- FWP_DEBUG("Service vres negotiated\n");
return 0;
}
-
-/**
- * fwp_mngt_input
- *
- * Function waits for remote or local message
- *
- * @msgb received message
- * \return
- * On success, it returns 0 and the pointer to received message in msgb parameter.
- * On error, it returns negative error code
- *
- */
-int fwp_mngr_input(struct fwp_msgb **pmsgb)
+#endif
+
+struct frm_fwp_priv priv = {
+ .rate_mbps = 1,
+ .erp_ofdm = false,
+ .short_preamble = false,
+};
+
+static const struct fres_res_manager frm = {
+ .res_type = FRSH_RT_NETWORK,
+ .res_id = FRSH_NETPF_FWP,
+ //.admission_test = dummy_admission_test,
+ .name = "WLAN",
+ .admission_test = fwp_admctrl_utilization,
+ .priv = &priv,
+};
+
+static struct option long_opts[] = {
+ { "loglevel", required_argument, 0, 'l' },
+ { "bitrate", required_argument, 0, 'b' },
+ { "ofdm", no_argument, 0, 'o' },
+ { "short-preamble", no_argument, 0, 's' },
+ { 0, 0, 0, 0}
+};
+
+static void
+usage(void)
{
- struct fwp_msgb *msgb;
- struct sockaddr_in *peer_in;
- int len, size;
- fd_set fdset;
-
- memcpy(&fdset, &fwp_input_fdset, sizeof(fd_set));
- FWP_DEBUG("Waiting for messages\n");
-
- if (select(getdtablesize()+1, &fdset, (fd_set *)0,
- (fd_set *)0, NULL) < 0){
-
- perror("Error in select");
- return (-errno);
- }
-
- if (FD_ISSET(fwp_lsockfd, &fdset)){
- FWP_DEBUG("Management message received from local socket\n");
- _fwp_recvfrom(len, fwp_lsockfd, buffer, FWP_MTU, 0,
- peer.addr, &peer.addrlen);
- size = 0;
- }
- else {
- FWP_DEBUG("Management message received from remote socket\n");
- _fwp_recvfrom(len, fwp_rsockfd, buffer, FWP_MTU, 0,
- peer.addr, &peer.addrlen);
-
- /* we have to set UDP port fwp agent is listening on for
- * responses from AP
- * */
- peer_in = (struct sockaddr_in*) peer.addr;
- peer_in->sin_port = htons(FWP_AGENT_UDP_PORT);
- size = sizeof(struct fwp_sockaddr);
- }
-
- FWP_DEBUG("Creating fwp msgb len=%d\n",len);
- /* For future: fwp_socket could be allocated behind data in msgb*/
- if (!(msgb = fwp_msgb_alloc(size))) {
- perror("No memory available.\n");
- return -ENOMEM;
- }
- /*memcpy(fwp_msgb_put(msgb, len), buffer, len); */
- msgb->data = buffer;
- fwp_msgb_put(msgb, len);
- msgb->peer = &peer;
-
- *pmsgb = msgb;
- return (0);
+ printf("usage: fwpmngr [ options ]\n");
+ printf(" -l, --loglevel <number>|<domain>=<number>,...\n");
+ printf(" -b, --bitrate <mbits/s>\n");
+ printf(" -o, --ofdm\n");
+ printf(" -s, --short-preamble\n");
+ printf(" -h, --help\n");
}
-int
-fwp_mngr_contract_negt_response(fwp_contract_data_t *contdata)
+int main(int argc, char *argv[])
{
- struct fwp_msgb *msgb;
-
- if (!(msgb = fwp_msgb_alloc(sizeof(struct fwp_msg_header) +
- sizeof(struct fwp_msg_vres_params)))) {
-
- fprintf(stderr, "No memory available.\n");
- return -ENOMEM;
+ forb_orb orb;
+ int ret;
+ forb_init_attr_t attr = { .orb_id = "org.frescor.frm.fwp" };
+ int opt;
+ bool opt_daemon = false;
+ char *opt_pidfile = NULL;
+
+ if (getenv("FWP_BYPASS"))
+ priv.bypass = true;
+
+
+ while ((opt = getopt_long(argc, argv, "b:d:hl:os", &long_opts[0], NULL)) != EOF) {
+ switch (opt) {
+ case 'd':
+ opt_daemon = true;
+ opt_pidfile = optarg;
+ break;
+ case 'l':
+ ul_log_domain_arg2levels(optarg);
+ break;
+ case 'b':
+ priv.rate_mbps = atol(optarg);
+ break;
+ case 's':
+ priv.short_preamble = true;
+ break;
+ case 'o':
+ priv.erp_ofdm = true;
+ break;
+ case 'h':
+ /*default:*/
+ usage();
+ exit(opt == 'h' ? 0 : 1);
+ }
}
-
- fwp_msg_header_deflate(msgb->tail, FWP_CONTNEGT_RES,
- &contdata->contract_call_id);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_header));
- fwp_msg_vres_params_deflate(msgb->tail, contdata->status,
- &contdata->vres_params);
- fwp_msgb_put(msgb, sizeof(struct fwp_msg_vres_params));
-
- msgb->peer = &contdata->agent->addr;
- /* TODO: add sending to local app through unix socket */
- _fwp_vres_send(service_vresd, msgb);
- return 0;
-}
-static int fwp_mngr_contract_accept(fwp_contract_data_t *contdata)
-{
- fwp_agent_data_t *agdata;
+ if (opt_daemon)
+ forb_daemon_prepare(opt_pidfile);
- if (contdata->status != FWP_CONT_NEGOTIATED) {
- return -1;
- }
+ orb = forb_init(&argc, &argv, &attr);
+ if (!orb) error(1, errno, "forb_init");
- agdata = contdata->agent;
- if (agdata) {
- fwp_contract_table_insert(&agdata->contract_table, contdata);
- }
- return 0;
-}
+ fres_block_register_fwp();
+ ret = frm_register_and_run(orb, &frm);
-int fwp_mngr_contract_negt_request(fwp_msgb_t *msgb, fwp_appcall_id_t *appcall_id,
- fwp_contract_data_t **contract_data)
-{
- fwp_contract_t contract;
- fwp_contract_data_t *contdata;
-
- /* deserialize contract from message */
- fwp_msg_contract_inflate(msgb->data, &contract);
- fwp_msgb_pull(msgb, sizeof(struct fwp_msg_contract));
-
- /* prepare contract data structure */
- contdata = (fwp_contract_data_t*) malloc(sizeof(fwp_contract_data_t));
- /* copy contract to contract_data */
- memcpy(&contdata->contract, &contract, sizeof(contdata->contract));
- /* set pointer to agent data */
- contdata->agent = fwp_agent_table_find(msgb->peer);
- /* set appid and hid */
- contdata->contract_call_id = *appcall_id;
- contdata->status = FWP_CONT_REQUESTED;
-
- fwp_msgb_free(msgb);
-
- /* put contract data into contract requested list */
- /*fwp_contractlist_insert(&contractlist_req, contdata);*/
- *contract_data = contdata;
-
- return 0;
-}
-
-static void fwp_mngr_msg_handler(struct fwp_msgb *msgb)
-{
- unsigned int code;
- fwp_appcall_id_t appcall_id;
-
- fwp_msg_header_inflate(msgb->data, &code, &appcall_id);
- fwp_msgb_pull(msgb, sizeof(struct fwp_msg_header));
- FWP_DEBUG("code = %d , appid = %d callid = %d\n", code,
- appcall_id.appid, appcall_id.callid);
-
- fwp_agent_table_insert(msgb->peer);
-
- switch (code) {
- case FWP_CONTNEGT_REQ:
- FWP_DEBUG("Negotiation Request received\n");
- fwp_mngr_contract_negt_request(msgb, &appcall_id,
- &contract_req);
- FWP_DEBUG("Executing admission control test\n");
- fwp_admctrl_test(contract_req);
-
- /* right now simply add to contract table if negotiated */
- //fwp_mngr_contract_accept(&msgb->peer, contract_req);
-
- FWP_DEBUG("Preparing NEGT_RES msg\n");
- fwp_mngr_contract_negt_response(contract_req);
- break;
- default:
- printf("Invalid message\n.");
- fwp_msgb_free(msgb);
+ if (ret != 0) {
+ error(1, errno, "frm_generic_run");
}
-}
-
-void fwp_mngr()
-{
- struct fwp_msgb *msgb;
-
- /* start admission control thread */
- while (1 /*exit_flag*/){
- fwp_mngr_input(&msgb);
- if (msgb)
- fwp_mngr_msg_handler(msgb);
- FWP_DEBUG("Mngr prepared to wait for next msg.\n");
- }
-}
-
-int main()
-{
- if (fwp_init() < 0) {
- fprintf(stderr,"FWP initialization failed.\n");
- exit(1);
-
- }
-
- if (fwp_mngr_init() < 0) {
- fprintf(stderr,"FWP manager initialization failed.\n");
- exit(1);
-
- }
-
- /* execute agent function */
- fwp_mngr();
-
+
return 0;
}