model/ns3-socket-fd-factory.cc
changeset 66 2fe1f3e576c9
parent 63 e89dca438df6
     1.1 --- a/model/ns3-socket-fd-factory.cc	Mon Apr 18 12:13:02 2011 +0200
     1.2 +++ b/model/ns3-socket-fd-factory.cc	Thu May 05 09:28:21 2011 +0200
     1.3 @@ -3,7 +3,7 @@
     1.4  #include "unix-socket-fd.h"
     1.5  #include "unix-datagram-socket-fd.h"
     1.6  #include "unix-stream-socket-fd.h"
     1.7 -#include "netlink-socket-factory.h"
     1.8 +#include "ns3/netlink-socket-factory.h"
     1.9  #include "ns3/socket-factory.h"
    1.10  #include "ns3/socket.h"
    1.11  #include "ns3/uinteger.h"
    1.12 @@ -29,36 +29,52 @@
    1.13  UnixFd *
    1.14  Ns3SocketFdFactory::CreateSocket (int domain, int type, int protocol)
    1.15  {
    1.16 -  NS_ASSERT (domain == PF_INET || domain == PF_NETLINK || domain == PF_INET6);
    1.17 -
    1.18    UnixSocketFd *socket = 0;
    1.19    Ptr<Socket> sock;
    1.20  
    1.21 -  switch (type) {
    1.22 -  case SOCK_DGRAM: {
    1.23 -    TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
    1.24 -    Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
    1.25 -    sock = factory->CreateSocket ();
    1.26 -    socket = new UnixDatagramSocketFd (sock);
    1.27 -  } break;
    1.28 -  case SOCK_RAW: {
    1.29 -    TypeId tid = TypeId::LookupByName ("ns3::Ipv4RawSocketFactory");
    1.30 -    Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
    1.31 -    sock = factory->CreateSocket ();
    1.32 -    sock->SetAttribute ("Protocol", UintegerValue (protocol));
    1.33 -    socket = new UnixDatagramSocketFd (sock);
    1.34 -  } break;
    1.35 -  case SOCK_STREAM: {
    1.36 -    TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
    1.37 -    Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
    1.38 -    sock = factory->CreateSocket ();
    1.39 -    socket = new UnixStreamSocketFd (sock);
    1.40 -  } break;
    1.41 -    default:
    1.42 -      // XXX insert netlink creation here.
    1.43 -      NS_FATAL_ERROR ("missing socket type");
    1.44 -      break;
    1.45 -  }
    1.46 +  if (domain == PF_INET)
    1.47 +    {
    1.48 +      switch (type) {
    1.49 +      case SOCK_DGRAM: {
    1.50 +	TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
    1.51 +	Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
    1.52 +	sock = factory->CreateSocket ();
    1.53 +	socket = new UnixDatagramSocketFd (sock);
    1.54 +      } break;
    1.55 +      case SOCK_RAW: {
    1.56 +	TypeId tid = TypeId::LookupByName ("ns3::Ipv4RawSocketFactory");
    1.57 +	Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
    1.58 +	sock = factory->CreateSocket ();
    1.59 +	sock->SetAttribute ("Protocol", UintegerValue (protocol));
    1.60 +	socket = new UnixDatagramSocketFd (sock);
    1.61 +      } break;
    1.62 +      case SOCK_STREAM: {
    1.63 +	TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
    1.64 +	Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
    1.65 +	sock = factory->CreateSocket ();
    1.66 +	socket = new UnixStreamSocketFd (sock);
    1.67 +      } break;
    1.68 +      default:
    1.69 +	NS_FATAL_ERROR ("missing socket type");
    1.70 +	break;
    1.71 +      }
    1.72 +    }
    1.73 +  else if (domain == PF_NETLINK)
    1.74 +    {
    1.75 +      switch (type) {
    1.76 +      case SOCK_DGRAM: {
    1.77 +	sock = m_netlink->CreateSocket ();
    1.78 +	socket = new UnixDatagramSocketFd (sock);
    1.79 +      } break;
    1.80 +      default:
    1.81 +	NS_FATAL_ERROR ("missing socket type");
    1.82 +	break;
    1.83 +      }
    1.84 +    }
    1.85 +  else
    1.86 +    {
    1.87 +      NS_FATAL_ERROR ("unsupported domain");
    1.88 +    }
    1.89  
    1.90    return socket;
    1.91  }