From 6940ab33b5009b79c3141dde7f98ea78a2662449 Mon Sep 17 00:00:00 2001 From: Sebastien Braun Date: Mon, 12 Jul 2010 04:15:13 +0200 Subject: Implement multicast transfer protocol. --- .../mcast/trial_programs/McastConfigArgParser.cpp | 151 +++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/net/mcast/trial_programs/McastConfigArgParser.cpp (limited to 'src/net/mcast/trial_programs/McastConfigArgParser.cpp') diff --git a/src/net/mcast/trial_programs/McastConfigArgParser.cpp b/src/net/mcast/trial_programs/McastConfigArgParser.cpp new file mode 100644 index 0000000..8849544 --- /dev/null +++ b/src/net/mcast/trial_programs/McastConfigArgParser.cpp @@ -0,0 +1,151 @@ +/* +# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your suggestions, praise, or complaints to feedback@openslx.org +# +# General information about OpenSLX can be found at http://openslx.org/ +# ----------------------------------------------------------------------------- +# src/net/mcast/trial_programs/McastConfigArgParser.cpp +# - Parse common Multicast Configuration CLI arguments +# ----------------------------------------------------------------------------- +*/ + +#include + +#include + +#include "McastConfigArgParser.h" + +using namespace std; + +bool parseMcastConfigArg(QStringList::iterator& i, QStringList::iterator const& end, McastConfiguration* config) +{ + QString arg = *i; + + if (arg == "-addr") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + config->multicastAddress(*i); + } + else if (arg == "-dport") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + bool ok; + quint16 dport = (quint16)i->toInt(&ok); + if (!ok) + { + cerr << "Error: dport is not an integer" << endl; + return false; + } + config->multicastDPort(dport); + } + else if (arg == "-sport") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + bool ok; + quint16 sport = (quint16)i->toInt(&ok); + if (!ok) + { + cerr << "Error: sport is not an integer" << endl; + return false; + } + config->multicastSPort(sport); + } + else if (arg == "-mtu") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + bool ok; + quint16 mtu = (quint16)i->toInt(&ok); + if (!ok) + { + cerr << "Error: MTU is not an integer" << endl; + return false; + } + config->multicastMTU(mtu); + } + else if (arg == "-rate") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + bool ok; + quint32 rate = i->toInt(&ok); + if (!ok) + { + cerr << "Error: Rate is not an integer" << endl; + return false; + } + config->multicastRate(rate); + } + else if (arg == "-winsize") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + bool ok; + quint16 winsize = (quint16)i->toInt(&ok); + if (!ok) + { + cerr << "Error: Winsize is not an integer" << endl; + return false; + } + config->multicastWinSize(winsize); + } + else if (arg == "-udp") + { + config->multicastUseUDP(true); + } + else if (arg == "-udp-port") + { + i++; + if(i == end) + { + cerr << "Option " << arg.toLatin1().constData() << " is missing argument" << endl; + return false; + } + bool ok; + quint16 udpport = (quint16)i->toInt(&ok); + if (!ok) + { + cerr << "Error: UDP-Port is not an integer" << endl; + return false; + } + config->multicastUDPPort(udpport); + } + else + { + return false; + } + + return true; +} -- cgit v1.2.3-55-g7522 From b4059aff0fbc54ba67fae57c743f5900e7b73f92 Mon Sep 17 00:00:00 2001 From: Sebastien Braun Date: Wed, 14 Jul 2010 16:10:00 +0200 Subject: Make UDP encapsulation correctly configurable. --- src/net/mcast/McastConfiguration.h | 26 +++++++++++++++------- src/net/mcast/McastConstants.h | 1 + src/net/mcast/McastPGMSocket.cpp | 21 +++++++++++++++-- .../mcast/trial_programs/McastConfigArgParser.cpp | 6 ++++- 4 files changed, 43 insertions(+), 11 deletions(-) (limited to 'src/net/mcast/trial_programs/McastConfigArgParser.cpp') diff --git a/src/net/mcast/McastConfiguration.h b/src/net/mcast/McastConfiguration.h index a609ce1..c32ac4f 100644 --- a/src/net/mcast/McastConfiguration.h +++ b/src/net/mcast/McastConfiguration.h @@ -35,8 +35,8 @@ public: _multicastDPort(DEFAULT_MULTICAST_DPORT), _multicastWinSize(DEFAULT_MULTICAST_WSIZ), _multicastMTU(DEFAULT_MULTICAST_MTU), - _multicastUDPPort(DEFAULT_MULTICAST_UDPPORT), - _multicastUseUDP(false) + _multicastUDPPortBase(DEFAULT_MULTICAST_UDPPORT), + _multicastUseUDP(DEFAULT_MULTICAST_USEUDP) { } @@ -48,7 +48,7 @@ public: _multicastDPort(other._multicastDPort), _multicastWinSize(other._multicastWinSize), _multicastMTU(other._multicastMTU), - _multicastUDPPort(other._multicastUDPPort), + _multicastUDPPortBase(other._multicastUDPPortBase), _multicastUseUDP(other._multicastUseUDP) { } @@ -127,16 +127,26 @@ public: return this; } - bool multicastUDPPort() const + quint16 multicastUDPPortBase() const { - return _multicastUDPPort; + return _multicastUDPPortBase; } - McastConfiguration* multicastUDPPort(quint16 port) + McastConfiguration* multicastUDPPortBase(quint16 port) { - _multicastUDPPort = port; + _multicastUDPPortBase = port; return this; } + quint16 multicastUDPUPort() const + { + return _multicastUDPPortBase; + } + + quint16 multicastUDPMPort() const + { + return _multicastUDPPortBase + 1; + } + void commit() { emit changed(); @@ -152,7 +162,7 @@ private: quint16 _multicastDPort; quint16 _multicastWinSize; quint16 _multicastMTU; - quint16 _multicastUDPPort; + quint16 _multicastUDPPortBase; bool _multicastUseUDP; }; diff --git a/src/net/mcast/McastConstants.h b/src/net/mcast/McastConstants.h index 712a0d5..9913457 100644 --- a/src/net/mcast/McastConstants.h +++ b/src/net/mcast/McastConstants.h @@ -23,6 +23,7 @@ #define DEFAULT_MULTICAST_ADDRESS ";239.255.220.207" #define DEFAULT_MULTICAST_SPORT 6964 #define DEFAULT_MULTICAST_DPORT 6965 +#define DEFAULT_MULTICAST_USEUDP true #define DEFAULT_MULTICAST_UDPPORT 6966 #define DEFAULT_MULTICAST_RATE (100*1024) #define DEFAULT_MULTICAST_WSIZ 3000 diff --git a/src/net/mcast/McastPGMSocket.cpp b/src/net/mcast/McastPGMSocket.cpp index 0d6b694..41764d5 100644 --- a/src/net/mcast/McastPGMSocket.cpp +++ b/src/net/mcast/McastPGMSocket.cpp @@ -142,8 +142,15 @@ bool McastPGMSocket::open(McastConfiguration const* config, Direction direction) sa_family_t family = addrinfo->ai_send_addrs[0].gsr_group.ss_family; - good - = pgm_socket(&_priv->socket, family, SOCK_SEQPACKET, IPPROTO_PGM, &err); + if(config->multicastUseUDP()) + { + good = pgm_socket(&_priv->socket, family, SOCK_SEQPACKET, IPPROTO_UDP, &err); + } + else + { + good = pgm_socket(&_priv->socket, family, SOCK_SEQPACKET, IPPROTO_PGM, &err); + } + if (!good) { qCritical() << "Could not open socket: PGM Error: " << err->message; @@ -209,6 +216,16 @@ bool McastPGMSocket::open(McastConfiguration const* config, Direction direction) int const mtu = config->multicastMTU(); pgm_setsockopt(_priv->socket, PGM_MTU, &mtu, sizeof(mtu)); + // UDP Encapsulation + if(config->multicastUseUDP()) + { + const quint16 uport = config->multicastUDPUPort(); + const quint16 mport = config->multicastUDPMPort(); + + pgm_setsockopt(_priv->socket, PGM_UDP_ENCAP_MCAST_PORT, &mport, sizeof(mport)); + pgm_setsockopt(_priv->socket, PGM_UDP_ENCAP_UCAST_PORT, &uport, sizeof(uport)); + } + pgm_sockaddr_t addr; addr.sa_addr.sport = config->multicastSPort(); addr.sa_port = config->multicastDPort(); diff --git a/src/net/mcast/trial_programs/McastConfigArgParser.cpp b/src/net/mcast/trial_programs/McastConfigArgParser.cpp index 8849544..efea0b5 100644 --- a/src/net/mcast/trial_programs/McastConfigArgParser.cpp +++ b/src/net/mcast/trial_programs/McastConfigArgParser.cpp @@ -125,6 +125,10 @@ bool parseMcastConfigArg(QStringList::iterator& i, QStringList::iterator const& { config->multicastUseUDP(true); } + else if (arg == "-no-udp") + { + config->multicastUseUDP(false); + } else if (arg == "-udp-port") { i++; @@ -140,7 +144,7 @@ bool parseMcastConfigArg(QStringList::iterator& i, QStringList::iterator const& cerr << "Error: UDP-Port is not an integer" << endl; return false; } - config->multicastUDPPort(udpport); + config->multicastUDPPortBase(udpport); } else { -- cgit v1.2.3-55-g7522 From 4bedfeeaa534e5e59b7fad745c5be0d6b7d587df Mon Sep 17 00:00:00 2001 From: Sebastien Braun Date: Wed, 14 Jul 2010 16:13:57 +0200 Subject: Make interface configurable. --- src/net/mcast/McastConfiguration.h | 13 +++++++++++++ src/net/mcast/McastConstants.h | 3 ++- src/net/mcast/McastPGMSocket.cpp | 2 +- src/net/mcast/trial_programs/McastConfigArgParser.cpp | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/net/mcast/trial_programs/McastConfigArgParser.cpp') diff --git a/src/net/mcast/McastConfiguration.h b/src/net/mcast/McastConfiguration.h index c32ac4f..4e0e2ad 100644 --- a/src/net/mcast/McastConfiguration.h +++ b/src/net/mcast/McastConfiguration.h @@ -29,6 +29,7 @@ Q_OBJECT public: McastConfiguration(QObject* parent = 0) : QObject(parent), + _multicastInterface(DEFAULT_MULTICAST_INTERFACE), _multicastAddress(DEFAULT_MULTICAST_ADDRESS), _multicastRate(DEFAULT_MULTICAST_RATE), _multicastSPort(DEFAULT_MULTICAST_SPORT), @@ -41,6 +42,7 @@ public: } McastConfiguration(McastConfiguration const& other) : + _multicastInterface(other._multicastInterface), QObject(), _multicastAddress(other._multicastAddress), _multicastRate(other._multicastRate), @@ -137,6 +139,16 @@ public: return this; } + QString multicastInterface() const + { + return _multicastInterface; + } + McastConfiguration* multicastInterface(QString const& interface) + { + _multicastInterface = interface; + return this; + } + quint16 multicastUDPUPort() const { return _multicastUDPPortBase; @@ -156,6 +168,7 @@ signals: void changed(); private: + QString _multicastInterface; QString _multicastAddress; quint32 _multicastRate; quint16 _multicastSPort; diff --git a/src/net/mcast/McastConstants.h b/src/net/mcast/McastConstants.h index 9913457..b4c71a5 100644 --- a/src/net/mcast/McastConstants.h +++ b/src/net/mcast/McastConstants.h @@ -20,7 +20,8 @@ #include #define MCASTFT_MAGIC UINT64_C(0x6d60ad83825fb7f9) -#define DEFAULT_MULTICAST_ADDRESS ";239.255.220.207" +#define DEFAULT_MULTICAST_INTERFACE "" +#define DEFAULT_MULTICAST_ADDRESS "239.255.220.207" #define DEFAULT_MULTICAST_SPORT 6964 #define DEFAULT_MULTICAST_DPORT 6965 #define DEFAULT_MULTICAST_USEUDP true diff --git a/src/net/mcast/McastPGMSocket.cpp b/src/net/mcast/McastPGMSocket.cpp index 41764d5..ebf6ae7 100644 --- a/src/net/mcast/McastPGMSocket.cpp +++ b/src/net/mcast/McastPGMSocket.cpp @@ -132,7 +132,7 @@ bool McastPGMSocket::open(McastConfiguration const* config, Direction direction) pgm_addrinfo_t* addrinfo; // parse the address string - good = pgm_getaddrinfo(config->multicastAddress().toLatin1().constData(), + good = pgm_getaddrinfo((config->multicastInterface() + ";" + config->multicastAddress()).toLatin1().constData(), 0, &addrinfo, &err); if (!good) { diff --git a/src/net/mcast/trial_programs/McastConfigArgParser.cpp b/src/net/mcast/trial_programs/McastConfigArgParser.cpp index efea0b5..881f728 100644 --- a/src/net/mcast/trial_programs/McastConfigArgParser.cpp +++ b/src/net/mcast/trial_programs/McastConfigArgParser.cpp @@ -146,6 +146,16 @@ bool parseMcastConfigArg(QStringList::iterator& i, QStringList::iterator const& } config->multicastUDPPortBase(udpport); } + else if (arg == "-intf") + { + i++; + if (i == end) + { + cerr << "Option " << arg.toLatin1().constData() << "is missing argument" << endl; + return false; + } + config->multicastInterface(*i); + } else { return false; -- cgit v1.2.3-55-g7522