Index: source/ariba/communication/BaseCommunication.h
===================================================================
--- source/ariba/communication/BaseCommunication.h	(revision 12775)
+++ source/ariba/communication/BaseCommunication.h	(revision 2378)
@@ -1,3 +1,3 @@
-// [License]
+// [Licence]
 // The Ariba-Underlay Copyright
 //
@@ -35,12 +35,11 @@
 // official policies, either expressed or implied, of the Institute of
 // Telematics.
-// [License]
+// [Licence]
 
 #ifndef BASECOMMUNICATION_H_
 #define BASECOMMUNICATION_H_
 
-// boost & std includes
-#include <boost/unordered_map.hpp>
-#include <boost/unordered_set.hpp>
+#include <ext/hash_map>
+#include <ext/hash_set>
 #include <map>
 #include <set>
@@ -50,62 +49,65 @@
 #include <boost/foreach.hpp>
 
-#ifdef ECLIPSE_PARSER
-    #define foreach(a, b) for(a : b)
-#else
-    #define foreach(a, b) BOOST_FOREACH(a, b)
-#endif
-
-// utilities
 #include "ariba/utility/types.h"
-#include "ariba/utility/messages/MessageReceiver.h"
+#include "ariba/utility/messages.h"
 #include "ariba/utility/logging/Logging.h"
 #include "ariba/utility/misc/Demultiplexer.hpp"
-#include "ariba/utility/system/SystemEventListener.h"
-
-// new transport and addressing
-#include "ariba/utility/transport/transport_peer.hpp"
-#include "ariba/utility/transport/interfaces/transport_connection.hpp"
-#include "ariba/utility/transport/interfaces/transport_listener.hpp"
-#include "ariba/utility/addressing2/endpoint.hpp"
-
-// communication
+
 #include "ariba/communication/CommunicationEvents.h"
 #include "ariba/communication/EndpointDescriptor.h"
-#include "ariba/communication/messages/AribaBaseMsg.h"
-
-// network changes
 #include "ariba/communication/networkinfo/NetworkChangeInterface.h"
 #include "ariba/communication/networkinfo/NetworkChangeDetection.h"
 #include "ariba/communication/networkinfo/NetworkInformation.h"
-
-namespace ariba {
-    class SideportListener;
-}
+#include "ariba/communication/networkinfo/AddressInformation.h"
+#include "ariba/communication/messages/AribaBaseMsg.h"
+#include "ariba/communication/modules/transport/TransportProtocol.h"
+#include "ariba/communication/modules/network/NetworkProtocol.h"
+#include "ariba/communication/modules/network/NetworkLocator.h"
+
+#ifndef UNDERLAY_OMNET
+  #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
+  #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
+#endif
+
+using __gnu_cxx::hash_set;
+using __gnu_cxx::hash_map;
+
+using std::cout;
+using std::set;
+using std::map;
+using std::vector;
+using std::pair;
+using std::make_pair;
+using std::find;
+
+using ariba::communication::NetworkChangeDetection;
+using ariba::communication::NetworkChangeInterface;
+using ariba::communication::NetworkInterfaceList;
+using ariba::communication::NetworkInformation;
+using ariba::communication::AddressInformation;
+using ariba::communication::AddressList;
+using ariba::communication::AribaBaseMsg;
+using ariba::communication::CommunicationEvents;
+
+using ariba::utility::Demultiplexer;
+using ariba::utility::QoSParameterSet;
+using ariba::utility::SecurityParameterSet;
+using ariba::utility::Address;
+using ariba::utility::LinkID;
+using ariba::utility::LinkIDs;
+using ariba::utility::Message;
+using ariba::utility::MessageReceiver;
+using ariba::utility::seqnum_t;
+
+using ariba::communication::TransportProtocol;
+using ariba::communication::NetworkProtocol;
+using ariba::communication::NetworkLocator;
+#ifndef UNDERLAY_OMNET
+  using ariba::communication::IPv4NetworkProtocol;
+  using ariba::communication::TCPTransport;
+#endif
 
 namespace ariba {
 namespace communication {
-
-
-class communication_message_not_sent: public std::runtime_error
-{
-public:
-    /** Takes a character string describing the error.  */
-    explicit communication_message_not_sent(const string& __arg)  :
-        std::runtime_error(__arg)
-    {
-    }
-    
-    virtual ~communication_message_not_sent() throw() {}
-};
-
-
-
-using namespace std;
-using namespace ariba::transport;
-using namespace ariba::utility;
-
-// use base ariba types (clarifies multiple definitions)
-using ariba::utility::Message;
-using ariba::utility::seqnum_t;
 
 /**
@@ -115,36 +117,36 @@
  * protocols and addressing schemes.
  *
- * @author Sebastian Mies, Christoph Mayer, Mario Hock
+ * @author Sebastian Mies, Christoph Mayer
  */
-class BaseCommunication:
-	public NetworkChangeInterface,
-	public transport_listener {
+class BaseCommunication : public MessageReceiver, NetworkChangeInterface {
 
 	use_logging_h(BaseCommunication);
-	friend class ariba::SideportListener;
 
 public:
-	/// Default ctor that just creates an non-functional base communication
-	BaseCommunication();
-
-	/// Default dtor that does nothing
+	/**
+	 * Constructs a Base Communication instance.
+	 * Listens default on port number 41402
+	 */
+	BaseCommunication(const NetworkLocator* _locallocator, const uint16_t _listenport);
+
+	/**
+	 * Destructs a Base Communication instance
+	 */
 	virtual ~BaseCommunication();
 
-	/// Startup the base communication, start modules etc.
-	void start(addressing2::EndpointSetPtr listen_on);
-
-	/// Stops the base communication, stop modules etc.
-	void stop();
-
-	/// Check whether the base communication has been started up
-	bool isStarted();
-
-	/// Establishes a link to another end-point.
-	const LinkID establishLink(const EndpointDescriptor& descriptor,
-		const LinkID& linkid = LinkID::UNSPECIFIED, const QoSParameterSet& qos =
-				QoSParameterSet::DEFAULT, const SecurityParameterSet& sec =
-				SecurityParameterSet::DEFAULT);
-
-	/// Drops a link
+	/**
+	 * Establishes a link to another end-point
+	 */
+	const LinkID establishLink(
+			const EndpointDescriptor& descriptor,
+			const QoSParameterSet& qos = QoSParameterSet::DEFAULT,
+			const SecurityParameterSet& sec = SecurityParameterSet::DEFAULT
+	);
+
+	/**
+	 * Drops a link
+	 *
+	 * @param The link id of the link that should be dropped
+	 */
 	void dropLink(const LinkID link);
 
@@ -156,8 +158,5 @@
 	 * @return A sequence number for this message
 	 */
-	seqnum_t sendMessage(const LinkID& lid,
-	        reboost::message_t message,
-	        uint8_t priority,
-	        bool bypass_overlay = false) throw(communication_message_not_sent);
+	seqnum_t sendMessage(const LinkID lid, const Message* message);
 
 	/**
@@ -167,6 +166,5 @@
 	 * @return The end-point descriptor of the link's end-point
 	 */
-	const EndpointDescriptor& getEndpointDescriptor(const LinkID link =
-			LinkID::UNSPECIFIED) const;
+	const EndpointDescriptor& getEndpointDescriptor( const LinkID link = LinkID::UNSPECIFIED ) const;
 
 	/**
@@ -176,5 +174,5 @@
 	 * @return List of LinkID
 	 */
-//	LinkIDs getLocalLinks(const address_v* addr) const;  // XXX aktuell
+	LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
 
 	/**
@@ -183,7 +181,5 @@
 	 * @param _receiver The receiving side
 	 */
-	void registerMessageReceiver(MessageReceiver* receiver) {
-		messageReceiver = receiver;
-	}
+	void registerMessageReceiver( MessageReceiver* _receiver );
 
 	/**
@@ -192,236 +188,140 @@
 	 * @param _receiver The receiving side
 	 */
-	void unregisterMessageReceiver(MessageReceiver* receiver) {
-		messageReceiver = NULL;
-	}
-
-	void registerEventListener(CommunicationEvents* _events);
-
-	void unregisterEventListener(CommunicationEvents* _events);
-
-	/**
-	 * called within the ASIO thread
-	 * when a message is received from underlay transport
-	 */ 
-	virtual void receive_message(transport_connection::sptr connection,
-		reboost::shared_buffer_t msg);
-
-    /**
-     * called within the ASIO thread
-     * when a connection is terminated (e.g. TCP close)
-     */ 
-    virtual void connection_terminated(transport_connection::sptr connection);
-
-    addressing2::EndpointPtr get_local_endpoint_of_link(const LinkID& linkid);
-    addressing2::EndpointPtr get_remote_endpoint_of_link(const LinkID& linkid);
-
-	
+	void unregisterMessageReceiver( MessageReceiver* _receiver );
+
+	void registerEventListener( CommunicationEvents* _events );
+	void unregisterEventListener( CommunicationEvents* _events );
+
 protected:
 
 	/**
-	 * called within the ARIBA thread (System Queue)
-	 * when a message is received from underlay transport
-	 */ 
-	void receiveMessage(transport_connection::sptr connection,
-	        reboost::shared_buffer_t message);
-	
-    /**
-     * called within the ARIBA thread (System Queue)
-     * when a connection is terminated (e.g. TCP close)
-     */ 
-    void connectionTerminated(transport_connection::sptr connection);
-	
-
-	/// called when a network interface change happens
-	virtual void onNetworkChange(
-		const NetworkChangeInterface::NetworkChangeInfo& info);
+	 * Called from the Transport when async items
+	 * from the SystemQueue are delivered
+	 */
+	virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node );
+
+	/**
+	 * Called when a network interface change happens
+	 */
+	virtual void onNetworkChange( const NetworkChangeInterface::NetworkChangeInfo& info );
 
 private:
-	/**
-	 * A link descriptor consisting of the end-point descriptor and currently
-	 * used underlay address.
+
+	/**
+	 * A link descriptor consisting of the
+	 * end-point descriptor and currently used locator and
+	 * message receiver
 	 */
 	class LinkDescriptor {
 	public:
-
-		/// default constructor
+		static const LinkDescriptor UNSPECIFIED;
+
 		LinkDescriptor() :
-			localLink(LinkID::UNSPECIFIED),
-			remoteLink(LinkID::UNSPECIFIED),
-			up(false) {
+			localLink(),
+			localLocator(NULL),
+			remoteLink(),
+			remoteLocator(NULL),
+			remoteEndpoint(EndpointDescriptor::UNSPECIFIED){
 		}
 
-		~LinkDescriptor()
-		{
-			if ( connection )
-			{
-			    connection->unregister_communication_link(&localLink);
-			}
+		LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
+				const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
+				const EndpointDescriptor& _remoteEndpoint ) :
+			localLink(_localLink),
+			localLocator(_localLocator),
+			remoteLink(_remoteLink),
+			remoteLocator(_remoteLocator),
+			remoteEndpoint(_remoteEndpoint){
 		}
 
+		LinkDescriptor( const LinkDescriptor& desc ) :
+			localLink(desc.localLink),
+			localLocator(desc.localLocator),
+			remoteLink(desc.remoteLink),
+			remoteLocator(desc.remoteLocator),
+			remoteEndpoint(desc.remoteEndpoint){
+		}
+
 		bool isUnspecified() const {
-			return (this == &UNSPECIFIED());
+			return (this == &UNSPECIFIED);
 		}
 
-		static LinkDescriptor& UNSPECIFIED(){
-			static LinkDescriptor* unspec = NULL;
-			if(unspec == NULL) unspec = new LinkDescriptor();
-			return *unspec;
-		}
-		
-		
-		transport_connection::sptr get_connection() const
-		{
-		    return connection;
-		}
-		
-		void set_connection(const transport_connection::sptr& conn)
-		{
-		    // unregister from old connection,
-		    // if any (but normally there shouldn't..)
-		    if ( connection )
-		    {
-		        connection->unregister_communication_link(&localLink);
-		    }
-
-		    // * set_connection *
-		    connection = conn;
-		    
-		    // register this link with the connection
-		    conn->register_communication_link(&localLink);
-		}
-
-		bool unspecified;
-
-		/// link identifiers
-		LinkID localLink;
-		addressing2::EndpointPtr localLocator;
-
-		/// used underlay addresses for the link
-		LinkID remoteLink;
-		addressing2::EndpointPtr remoteLocator;
-
-		/// the remote end-point descriptor
-		EndpointDescriptor remoteDescriptor;
-
-		/// flag, whether this link is up
-		bool up;
-		
-		
-	private:
-		/// connection if link is up
-		transport_connection::sptr connection;
+		LinkID 			localLink;
+		const NetworkLocator* 	localLocator;
+		LinkID 			remoteLink;
+		const NetworkLocator* 	remoteLocator;
+		EndpointDescriptor 	remoteEndpoint;
 	};
 
-	/// Link management: list of links
-	typedef vector<LinkDescriptor*> LinkSet;
-
-	/// Link management: the set of currently managed links
+	/**
+	 * Link management: add a link
+	 */
+	void addLink( const LinkDescriptor& link );
+
+	/**
+	 * Link management: remove alink
+	 */
+	void removeLink( const LinkID& localLink );
+
+	/**
+	 * Link management: get link information using the local link
+	 */
+	LinkDescriptor& queryLocalLink( const LinkID& localLink ) const;
+
+	/**
+	 * Link management: get link information using the remote link
+	 */
+	LinkDescriptor& queryRemoteLink( const LinkID& remoteLink ) const;
+
+	/**
+	 * Link management: list of links
+	 */
+	typedef vector<LinkDescriptor> LinkSet;
+
+	/**
+	 * Link management: the set of currently managed links
+	 */
 	LinkSet linkSet;
 
-	/// Link management: add a link
-	void addLink( LinkDescriptor* link );
-
-	/// Link management: remove a link
-	void removeLink(const LinkID& localLink);
-
-	/// Link management: get link information using the local link
-	LinkDescriptor& queryLocalLink(const LinkID& localLink) const;
-
-	/// Link management: get link information using the remote link
-	LinkDescriptor& queryRemoteLink(const LinkID& remoteLink) const;
-
-	/// The local end-point descriptor
+	/**
+	 * The message receiver
+	 */
+	MessageReceiver* messageReceiver;
+
+	/**
+	 * The local end-point descriptor
+	 */
 	EndpointDescriptor localDescriptor;
-	
-	/**
-	 * endpoint_set holding the addresses of the "server"-sockets,
-	 * ---> that should be opened
-	 * 
-	 * (e.g. 0.0.0.0:41322)
-	 */
-	addressing2::EndpointSetPtr listenOn_endpoints;
-	
-    /**
-     * endpoint_set holding the addresses of the "server"-sockets,
-     * ---> that are actually open
-     * 
-     * (e.g. 0.0.0.0:41322)
-     * 
-     * XXX should only be in transport_peer
-     */
-	addressing2::EndpointSetPtr active_listenOn_endpoints;
-	
-    /**
-     * endpoint_set holding the addresses of the "server"-sockets,
-     * ---> here the discovered "addressable" addresses are stored
-     * 
-     * (e.g. 192.168.0.5:41322)
-     * 
-     * XXX should only be in localDescriptor
-     */
-	addressing2::EndpointSetPtr local_endpoints;
-
-	/// network change detector
+
+	/**
+	 * Network information and protocol
+	 */
+	NetworkProtocol* network;
+
+	/**
+	 * Transport information and protocol
+	 */
+	TransportProtocol* transport;
+
+#ifndef UNDERLAY_OMNET
+	/**
+	 * Detect changes in the routing/interface, etc.
+	 * stuff needed for mobility detection
+	 */
 	NetworkChangeDetection networkMonitor;
-
-	/// list of all remote addresses of links to end-points
-	// XXX DEPRECATED
-//	class endpoint_reference {
-//	public:
-//		int count; ///< the number of open links to this end-point
-//		const address_v* endpoint; ///< the end-point itself
-//	};
-//	vector<endpoint_reference> remote_endpoints;
-
-	// XXX DEPRECATED
-//	/// adds an end-point to the list
-//	void add_endpoint( const address_v* endpoint );
-//
-//	/// removes an end-point from the list
-//	void remove_endpoint( const address_v* endpoint );
-
-	/// event listener
+#endif
+
+	/**
+	 * The local listen port
+	 */
+	uint16_t listenport;
+
 	typedef set<CommunicationEvents*> EventListenerSet;
 	EventListenerSet eventListener;
 
-	/// sequence numbers
 	seqnum_t currentSeqnum;
-
-	/// transport peer
-	transport_peer* transport;
-
-	/// the base overlay message receiver
-	MessageReceiver* messageReceiver;
-
-	
-	/* 
-	 * Sends a message over an existing link.
-	 *   ---> Adds Â»Link MessageÂ« Header
-	 */
-	bool send_over_link(
-	        const uint8_t type,
-	        reboost::message_t message,
-	        const LinkDescriptor& desc,
-	        const uint8_t priority);
-
-    /* 
-     * Sends a message to a known peer. (To all known endpoints.)
-     *   ---> Adds Â»Peer MessageÂ« Header
-     */
-	void send_to_peer(
-	        const uint8_t type,
-	        const PeerID& peer_id,
-	        reboost::message_t message,
-	        const EndpointDescriptor& endpoint,
-	        const uint8_t priority );
-	
-
-	/// state of the base communication
-	bool started;
-
 };
 
 }} // namespace ariba, communication
 
-#endif /* BASECOMMUNICATION_H_ */
+#endif /*BASECOMMUNICATION_H_*/
