summaryrefslogtreecommitdiff
path: root/cesar/maximus/ethernet/src/EthernetProcessor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/ethernet/src/EthernetProcessor.cpp')
-rw-r--r--cesar/maximus/ethernet/src/EthernetProcessor.cpp305
1 files changed, 0 insertions, 305 deletions
diff --git a/cesar/maximus/ethernet/src/EthernetProcessor.cpp b/cesar/maximus/ethernet/src/EthernetProcessor.cpp
deleted file mode 100644
index 1d7c7267ef..0000000000
--- a/cesar/maximus/ethernet/src/EthernetProcessor.cpp
+++ /dev/null
@@ -1,305 +0,0 @@
-/************************************************************************
- EthernetProcessor.cpp - Copyright buret
-
-Here you can write a license for your code, some comments or any other
-information you want to have in your generated code. To to this simply
-configure the "headings" directory in uml to point to a directory
-where you have your heading files.
-
-or you can just replace the contents of this file with your own.
-If you want to do this, this file is located at
-
-/usr/share/apps/umbrello/headings/heading.cpp
-
--->Code Generators searches for heading files based on the file extension
- i.e. it will look for a file name ending in ".h" to include in C++ header
- files, and for a file name ending in ".java" to include in all generated
- java code.
- If you name the file "heading.<extension>", Code Generator will always
- choose this file even if there are other files with the same extension in the
- directory. If you name the file something else, it must be the only one with that
- extension in the directory to guarantee that Code Generator will choose it.
-
-you can use variables in your heading files which are replaced at generation
-time. possible variables are : author, date, time, filename and filepath.
-just write %variable_name%
-
-This file was generated on %date% at %time%
-The original location of this file is /home/buret/eclipse/maximus/ethernet/src/EthernetProcessor.cpp
-**************************************************************************/
-
-#include "EthernetProcessor.h"
-
-#include "EtherSciMsg.h"
-#include "ISci.h"
-
-#include "Error.h"
-#include "Logger.h"
-
-#include <sys/socket.h> // for 'struct sockaddr'
-#include <linux/if.h>
-#include <linux/if_tun.h>
-#include <sys/ioctl.h>
-#include <fcntl.h> // for 'O_RDWR'
-#include <unistd.h> // for 'system()'
-using namespace std;
-
-
-// Constructors/Destructors
-//
-
-
-EthernetProcessor::EthernetProcessor ( ISci * p_sci ):
-mpSci(NULL),
-mInterfaceCb(NULL)
-{
- logFunction();
-
- if (NULL == p_sci)
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "SCI pointer is NULL", errno);
- }
- mpSci = p_sci;
- initAttributes();
-}
-
-
-void EthernetProcessor::initAttributes ( )
-{
- logFunction();
-
- registerEtherSciMsg();
-}
-
-
-EthernetProcessor::~EthernetProcessor ( )
-{
- logFunction();
-
- if (NULL != mpSci)
- {
- mpSci = NULL;
- }
- if (NULL != mInterfaceCb)
- {
- mInterfaceCb = NULL;
- }
-}
-
-
-//
-// Methods
-//
-
-
-// Other methods
-//
-
-
-// public methods
-//
-
-
-bool EthernetProcessor::init ( EtherCb interface_cb )
-{
- logFunction();
-
- if (NULL == interface_cb)
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "Callback function address is NULL", errno);
- }
- mInterfaceCb = interface_cb;
-
- return true;
-}
-
-
-EtherSciMsg * EthernetProcessor::createEther ( )
-{
- logFunction();
-
- return new EtherSciMsg(this);
-}
-
-
-bool EthernetProcessor::sendEther ( EtherSciMsg & ether_sci_msg )
-{
- logFunction();
- bool bSend = false;
-
- if ( fillEther(ether_sci_msg) && (0 != ether_sci_msg.getSciMsgStationId()) )
- {
- bSend = getSci()->sendSciMsg(ether_sci_msg);
- }
- if (!bSend)
- {
- throw Error(__PRETTY_FUNCTION__, "cannot send Ether SCI message", errno);
- }
-
- return bSend;
-}
-
-
-bool EthernetProcessor::receiveEther ( EtherSciMsg & ether_sci_msg )
-{
- logFunction();
-
- // Check Ether SCI message data length and data
- if ( (0 == ether_sci_msg.getSpecializedSciMsgDataLength())
- || (NULL == ether_sci_msg.getSpecializedSciMsgData()) )
- {
- errno = EINVAL;
- throw Error(__PRETTY_FUNCTION__, "received Ether SCI message is incorrect", errno);
- }
-
- // Go back up to user
- if (NULL != getInterfaceCb())
- {
- getInterfaceCb()(ether_sci_msg);
- }
-
- return true;
-}
-
-
-File_Descriptor EthernetProcessor::allocTap ( char * dev ) const
-{
- logFunction();
- int etherLogFileDescriptor = -1;
-
- if (0 > (etherLogFileDescriptor = open("/dev/net/tun", O_RDWR)))
- {
- throw Error(__PRETTY_FUNCTION__, "open /dev/net/tun failed", errno);
- }
- else
- {
- struct ifreq ifr;
- memset(&ifr, 0, sizeof(ifr));
- /* Flags:
- * IFF_TUN - TUN device (no Ethernet headers)
- * IFF_TAP - TAP device
- * IFF_NO_PI - Do not provide packet information
- */
- ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
- if (* dev)
- {
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
- }
- if (0 > ioctl(etherLogFileDescriptor, TUNSETIFF, (void *)&ifr))
- {
- close(etherLogFileDescriptor);
- etherLogFileDescriptor = -1;
- if (EPERM == errno)
- {
- throw Error(__PRETTY_FUNCTION__, "please launch the program with root rights", errno);
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "ioctl failed", errno);
- }
- }
- else
- {
- /* Set persistent status */
- if (0 > ioctl(etherLogFileDescriptor, TUNSETPERSIST, 1))
- {
- throw Error(__PRETTY_FUNCTION__, "enabling TUNSETPERSIST failed", errno);
- }
-
- /* We don't need checksums calculated for packets coming in this device */
- ioctl(etherLogFileDescriptor, TUNSETNOCSUM, 1);
-
- //system("wireshark");
- strcpy(dev, ifr.ifr_name);
- }
- }
-
- return etherLogFileDescriptor;
-}
-
-
-// private methods
-//
-
-
-void EthernetProcessor::registerEtherSciMsg ( )
-{
- logFunction();
-
- if (!getSci()->registerSpecializedSciMsg(SCI_MSG_TYPE_ETHERNET, new EtherSciMsg((IEthernet *)this)))
- {
- throw Error(__PRETTY_FUNCTION__, "cannot register Ether SCI message to SCI");
- }
-}
-
-
-bool EthernetProcessor::fillEther ( EtherSciMsg & ether_sci_msg ) const
-{
- logFunction();
- bool bFill = false;
-
- // Fill specialized SCI msg header
- //
- struct Ethernet_Header ethernetHeader;
- ethernetHeader.version = ether_sci_msg.getSpecializedSciMsgHeader().version;
- ethernetHeader.type = ether_sci_msg.getSpecializedSciMsgType();
- ethernetHeader.flags = ether_sci_msg.getFlags();
- ethernetHeader.reserved = ether_sci_msg.getSpecializedSciMsgHeader().reserved;
-
- // Set specialized SCI msg header
- //
- bFill = ether_sci_msg.setSpecializedSciMsgHeader(ethernetHeader);
-
- // Fill specialized SCI msg attributes:
- // - header size
- //
- bFill &= ether_sci_msg.setSpecializedSciMsgHeaderSize(sizeof(struct Ethernet_Header));
-
- // Fill SCI msg attributes:
- // - type
- //
- bFill &= ether_sci_msg.setSciMsgType(SCI_MSG_TYPE_ETHERNET);
- bFill &= getSci()->fillSciMsg(ether_sci_msg);
-
- return bFill;
-}
-
-
-// protected methods
-//
-
-
-// Accessor methods
-//
-
-
-// public attribute accessor methods
-//
-
-
-// private attribute accessor methods
-//
-
-
-ISci * EthernetProcessor::getSci ( ) const
-{
- if (NULL == mpSci)
- {
- throw Error(__PRETTY_FUNCTION__, "SCI pointer is NULL");
- }
-
- return mpSci;
-}
-
-
-EtherCb EthernetProcessor::getInterfaceCb ( ) const
-{
- return mInterfaceCb;
-}
-
-
-// protected attribute accessor methods
-//
-