NSIS-ka
A free C++ implementation of NSIS protocols

Changeset 4102


Ignore:
Timestamp:
Jul 16, 2009, 10:15:18 AM (8 years ago)
Author:
bless
Message:
Location:
qos-nslp/branches/20080820-configpar
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • qos-nslp/branches/20080820-configpar

  • qos-nslp/branches/20080820-configpar/include/QoS_NSLP_Client_API.h

    r3825 r4102  
    33
    44#include "QoS_NSLP_API.h"
     5#include "sessionid.h"
    56#include "qspec.h"
    67
     
    2425
    2526        /// send reservation from source to destination
    26         void send_reserve(appladdress &src, appladdress &dst, bool downstream, float bandwidth);
     27        ntlp::sessionid* send_reserve(appladdress &src, appladdress &dst, bool downstream, float bandwidth);
    2728
    2829        /// send query to trigger receiver initiated reserve from src to dest
    29         void send_query(appladdress &src, appladdress &dst, bool downstream, float bandwidth);
     30        ntlp::sessionid* send_query(appladdress &src, appladdress &dst, bool downstream, float bandwidth);
     31
     32        /// send tear of reservation from source to destination for given sid
     33        void send_tear(ntlp::sessionid *sid, appladdress &src, appladdress &dst, bool downstream, float bandwith = -1);
    3034
    3135        /// receive response
  • qos-nslp/branches/20080820-configpar/src

    • Property svn:ignore
      •  

        old new  
        44libqosnslp.a
        55qosnslp
         6client
  • qos-nslp/branches/20080820-configpar/src/QoS_NSLP_API.cpp

    r3825 r4102  
    1717#include <sys/un.h>
    1818#include <poll.h>
     19#include <errno.h>
    1920
    2021using namespace protlib::log;
     
    113114/**
    114115 * Receive PDU from UNIX domain socket
    115  * @param status success, failure or unknown
     116 * @param status if the received PDU has an informational element
     117 *               status will be set to its GIST error class code.
     118 *               In case a low level error occurrs status is set to -1
     119 *               and errno is set accordingly.
    116120 * @param timeout_ms poll timeout in milli seconds, specifying a negative timeout means infinite
    117121 */
     
    121125
    122126        if (client_sock < 0) {
     127                status = -1;
    123128                ERRLog("QoS NSLP API", "Couldn't establish connection to socket");
    124129                return;
     
    132137        res = poll(&pollfds, 1, timeout_ms);
    133138        if (res == 0) {
     139                errno = ETIMEDOUT;
     140                status = -1;
    134141                ERRLog("QoS NSLP API", "timed out");
    135142                return;
    136143        }
    137144        if (res == -1) {
     145                status = -1;
    138146                ERRLog("QoS NSLP API", "an error occurred");
    139147                return;
     
    146154        size_t nm_size = recv(client_sock, buffer, buf_size, 0);
    147155        if (nm_size <= 0) {
     156                status = -1;
    148157                ERRLog("QoS NSLP API", "lost connection");
    149158                return;
     
    207216
    208217        if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
    209                 ERRLog("QoS NSLP API", "socket() failed");
     218                ERRLog("QoS NSLP API", "socket() failed: " << strerror(errno));
    210219        else if (connect(sock, (struct sockaddr *) &daemon_addr, len) < 0) {
    211                 ERRLog("QoS NSLP API", "connect() failed");
     220                ERRLog("QoS NSLP API", "connect() failed: " << strerror(errno));
    212221                return -1;
    213222        }
  • qos-nslp/branches/20080820-configpar/src/QoS_NSLP_Client_API.cpp

    r3825 r4102  
    2929} // end destructor
    3030
    31 void QoS_NSLP_Client_API::send_reserve(appladdress &src, appladdress &dst, bool downstream, float bandwidth)
     31ntlp::sessionid*
     32QoS_NSLP_Client_API::send_reserve(appladdress &src, appladdress &dst, bool downstream, float bandwidth)
    3233{
    3334        DLog("QoS NSLP Client API", "Send QoS NSLP Reserve");
     
    6869                dst,
    6970                downstream);
     71
     72        return new_sid;
    7073}
    7174
    7275
    73 void
     76ntlp::sessionid*
    7477QoS_NSLP_Client_API::send_query(appladdress &src, appladdress &dst, bool downstream, float bandwidth)
    7578{
     
    111114                dst,
    112115                downstream);
     116
     117        return new_sid;
     118}
     119
     120void
     121QoS_NSLP_Client_API::send_tear(ntlp::sessionid *sid, appladdress &src, appladdress &dst, bool downstream, float bandwidth)
     122{
     123        DLog("QoS NSLP Client API", "Send QoS NSLP Tear (Tearing Reserve)");
     124
     125        sid_list sidl;
     126        rsn_list rsnl;
     127       
     128        /* create qspec pdu if a positive bandwith has been specified */
     129        /* otherwise the missing qspec pdu indicates to tear all allocated ressources */
     130        const int object_combination = 1;
     131        qspec_pdu* q_pdu = NULL;
     132        if (bandwidth >= 0) {
     133                q_pdu = new qspec_pdu(ms_sender_initiated_reservations, object_combination);
     134                qspec::qspec_object *qos_desired = new qspec::qspec_object(ot_qos_desired);
     135                qos_desired->set_parameter(new qspec::t_mod(bandwidth, 100000, bandwidth, 1500));
     136                q_pdu->set_object(qos_desired);
     137        }
     138
     139        send_pdu(*sid,
     140                known_nslp_pdu::RESERVE,
     141                q_pdu,
     142                false,  /* refresh */
     143                sidl,   /* SID List */
     144                rsnl,   /* RSN List */
     145                NULL,   /* info spec */
     146                false,  /* features in */
     147                false,  /* break flag */
     148                false,  /* request reduced refreshes */
     149                false,  /* reserve-init */
     150                true,   /* tear flag */
     151                false,  /* replace flag */
     152                false,  /* ack flag */
     153                false,  /* proxy flag */
     154                false,  /* scope flag */
     155                false,  /* incoming interface */
     156                false,  /* outgoing interface */
     157                src,
     158                dst,
     159                downstream);
    113160}
    114161
  • qos-nslp/branches/20080820-configpar/src/client.cpp

    r3825 r4102  
    3535#include <iostream>
    3636#include <cstdlib>
     37#include <cstring>
     38#include <errno.h>
    3739
    3840#include "QoS_NSLP_Client_API.h"
     41#include "sessionid.h"
    3942
    4043using namespace qos_nslp;
     
    4548const std::string sockname("/tmp/qos_nslp_socket");
    4649
     50/* This flag controls termination of the main loop.  */
     51volatile sig_atomic_t keep_going = 0;
     52
    4753logfile commonlog("", true, true);
    4854qos_nslp::log::logfile& qos_nslp::log::DefaultLog(commonlog);
     55
     56void catch_sigint(int sig)
     57{
     58        std::cerr << "Caught a SIGINT signal. Terminating..." << std::endl;
     59        keep_going = 0;
     60        signal(sig, catch_sigint);
     61}
     62
    4963
    5064int main(int argc, char *argv[])
     
    5569                return EXIT_FAILURE;
    5670        }
     71
     72        // Establish a handler for SIGINT signals (send on Ctrl-c)
     73        signal(SIGINT, catch_sigint);
    5774
    5875        // initalize netdb
     
    7087        // this sends a RESERVE message as reservation request for
    7188        // a data flow from src to dst
     89        ntlp::sessionid *gist_sid;
    7290        if (argc > 3 && strncasecmp("r", argv[3], 1) == 0)
    73                 client.send_query(src, dst, downstream, bandwidth);
     91                gist_sid = client.send_query(src, dst, downstream, bandwidth);
    7492        else
    75                 client.send_reserve(src, dst, downstream, bandwidth);
     93                gist_sid = client.send_reserve(src, dst, downstream, bandwidth);
    7694
    77         int status = 42;
     95        int status;
    7896        int timeout = 5000; // ms
    7997
     
    8199        client.recv_response(status, timeout);
    82100
    83         if (status == 2)
     101        if (status == 2) {
    84102                std::cout << "successful reservation" << std::endl;
     103                keep_going = 1;
     104        } else if (status >= 0)
     105                std::cout << "status of reservation request " << status << std::endl;
    85106        else
    86                 std::cout << "status of reservation request " << status << std::endl;
     107                std::cout << "An error occurred: " << std::strerror(errno) << std::endl;
    87108
    88         // wait forever - e.g., continue application processing
    89         while (true)
     109        // wait until Ctrl-c sets keep_going = 0 -- e.g., continue application processing
     110        while (keep_going)
    90111                sleep(1);
     112
     113        // If reservation has been successful tear down resources now
     114        if (status == 2) {
     115                client.send_tear(gist_sid, src, dst, downstream);
     116                // ... and wait 5000ms for confirmation
     117                client.recv_response(status, timeout);
     118        }
    91119
    92120        tsdb::end();
  • qos-nslp/branches/20080820-configpar/src/rmf.cpp

    r1504 r4102  
    1717
    1818using namespace protlib;
     19using namespace protlib::log;
    1920
    2021namespace qos_nslp {
     
    109110void rmf::process_qspec_in_query(qspec_pdu* q)
    110111{
     112  EVLog("QoS RMF", "QUERY ressources");
    111113
    112114}
     
    117119bool rmf::reserve_ressources(qspec_pdu* q)
    118120{
     121  EVLog("QoS RMF", "RESERVE ressources");
     122
    119123  return true;
    120124}
     
    125129void rmf::release_ressources(qspec_pdu* q)
    126130{
     131  EVLog("QoS RMF", "RELEASE ressources");
    127132
    128133}
  • qos-nslp/branches/20080820-configpar/src/start-qosnslp

    r3943 r4102  
    1 #!/bin/sh
     1#!/bin/bash
    22
    33LOGDIR=testing/logs
     
    1010done
    1111
     12# define a signal handler function
     13handle_sigint()
     14{
     15        true
     16}
     17
    1218# load kernel modules
    1319./loadmodules
    1420
    15 ./qosnslp $* 2>&1 | tee $LOGDIR/test-`date +"%F-%T"`-`hostname`-$$
     21# activate the signal handler
     22# This signal handler is called after all child processes (i.e. qosnslp)
     23# have been signaled SIGINT and have terminated and gives control back
     24# to the script
     25trap handle_sigint SIGINT
     26
     27./qosnslp $* 2>&1 | tee -i $LOGDIR/test-`date +"%F-%T"`-`hostname`-$$
    1628
    1729./flush
Note: See TracChangeset for help on using the changeset viewer.