Index: source/ariba/communication/BaseCommunication.h
===================================================================
--- source/ariba/communication/BaseCommunication.h	(revision 4983)
+++ source/ariba/communication/BaseCommunication.h	(revision 5284)
@@ -40,4 +40,5 @@
 #define BASECOMMUNICATION_H_
 
+// boost & std includes
 #include <ext/hash_map>
 #include <ext/hash_set>
@@ -49,65 +50,59 @@
 #include <boost/foreach.hpp>
 
+// utilities
 #include "ariba/utility/types.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/addressing/addressing.hpp"
+#include "ariba/utility/transport/transport.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"
 #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
+
+// deprecated
+//#include "ariba/communication/modules/transport/TransportProtocol.h"
+//#include "ariba/communication/modules/network/NetworkProtocol.h"
+//#include "ariba/communication/modules/network/NetworkLocator.h"
+
+// disabled
+//#ifndef UNDERLAY_OMNET
+//  #include "ariba/communication/modules/transport/tcp/TCPTransport.h"
+//  #include "ariba/communication/modules/network/ip/IPv4NetworkProtocol.h"
+//#endif
+
+// deprecated
+//using ariba::communication::TransportProtocol;
+//using ariba::communication::NetworkProtocol;
+//using ariba::communication::NetworkLocator;
+
+// disabled
+//#ifndef UNDERLAY_OMNET
+//  using ariba::communication::IPv4NetworkProtocol;
+//  using ariba::communication::TCPTransport;
+//#endif
 
 namespace ariba {
 namespace communication {
+
+using namespace std;
+using namespace ariba::addressing;
+using namespace ariba::transport;
+using namespace ariba::utility;
+
+// use base ariba types (clarifies multiple definitions)
+using ariba::utility::Message;
+using ariba::utility::seqnum_t;
 
 /**
@@ -119,50 +114,34 @@
  * @author Sebastian Mies, Christoph Mayer
  */
-class BaseCommunication : public MessageReceiver, NetworkChangeInterface {
+class BaseCommunication: public NetworkChangeInterface,
+	public SystemEventListener, public transport_listener {
 	use_logging_h(BaseCommunication);
+
 public:
-
-	/**
-	 * Default ctor that just creates an empty
-	 * non functional base communication
-	 */
+	/// Default ctor that just creates an non-functional base communication
 	BaseCommunication();
 
-	/**
-	 * Default dtor that does nothing
-	 */
+	/// Default dtor that does nothing
 	virtual ~BaseCommunication();
 
-	/**
-	 * Startup the base communication, start modules etc.
-	 */
-	void start(const NetworkLocator* _locallocator, const uint16_t _listenport);
-
-	/**
-	 * stop the base communication, stop modules etc.
-	 */
+	/// Startup the base communication, start modules etc.
+	void start();
+
+	/// Stops the base communication, stop modules etc.
 	void stop();
 
-	/*
-	 * Check whether the base communication has been started up
-	 */
+	/// Sets the endpoints
+	void setEndpoints( string& endpoints );
+
+	/// 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.
-	 *
-	 * @param The link id of the link that should be dropped
-	 */
+	/// 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
 	void dropLink(const LinkID link);
 
@@ -182,5 +161,6 @@
 	 * @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;
 
 	/**
@@ -190,5 +170,5 @@
 	 * @return List of LinkID
 	 */
-	LinkIDs getLocalLinks( const EndpointDescriptor& ep = EndpointDescriptor::UNSPECIFIED ) const;
+	LinkIDs getLocalLinks(const address_v* addr) const;
 
 	/**
@@ -197,5 +177,7 @@
 	 * @param _receiver The receiving side
 	 */
-	void registerMessageReceiver( MessageReceiver* _receiver );
+	void registerMessageReceiver(MessageReceiver* receiver) {
+		messageReceiver = receiver;
+	}
 
 	/**
@@ -204,28 +186,36 @@
 	 * @param _receiver The receiving side
 	 */
-	void unregisterMessageReceiver( MessageReceiver* _receiver );
-
-	void registerEventListener( CommunicationEvents* _events );
-	void unregisterEventListener( CommunicationEvents* _events );
+	void unregisterMessageReceiver(MessageReceiver* receiver) {
+		messageReceiver = NULL;
+	}
+
+	void registerEventListener(CommunicationEvents* _events);
+
+	void unregisterEventListener(CommunicationEvents* _events);
+
+public:
+
+	/// called when a system event is emitted by system queue
+	virtual void handleSystemEvent(const SystemEvent& event);
+
+	/// called when a message is received form transport_peer
+	virtual void receive_message(transport_protocol* transport,
+		const address_vf local, const address_vf remote, const uint8_t* data,
+		size_t size);
 
 protected:
 
-	/**
-	 * 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 );
+	/// handle received message from a transport module
+	void receiveMessage(const Message* message,
+		const address_v* local, const address_v* remote );
+
+	/// 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 locator and
-	 * message receiver
+	/**
+	 * A link descriptor consisting of the end-point descriptor and currently
+	 * used underlay address.
 	 */
 	class LinkDescriptor {
@@ -233,118 +223,80 @@
 		static const LinkDescriptor UNSPECIFIED;
 
+		/// default constructor
 		LinkDescriptor() :
-			localLink(LinkID::UNSPECIFIED),
-			localLocator(NULL),
-			remoteLink(LinkID::UNSPECIFIED),
-			remoteLocator(NULL),
-			remoteEndpoint(EndpointDescriptor::UNSPECIFIED),
-			linkup(false) {
+			localLink(LinkID::UNSPECIFIED), localLocator(NULL),
+			remoteLink(LinkID::UNSPECIFIED), remoteLocator(NULL),
+			remoteEndpoint(EndpointDescriptor::UNSPECIFIED), up(false) {
 		}
 
-		LinkDescriptor(const LinkID& _localLink, const NetworkLocator*& _localLocator,
-				const LinkID& _remoteLink, const NetworkLocator*& _remoteLocator,
-				const EndpointDescriptor& _remoteEndpoint, bool _linkup ) :
-			localLink(_localLink),
-			localLocator(_localLocator),
-			remoteLink(_remoteLink),
-			remoteLocator(_remoteLocator),
-			remoteEndpoint(_remoteEndpoint),
-			linkup(_linkup) {
+		~LinkDescriptor() {
+			if (localLocator!=NULL)  delete localLocator;
+			if (remoteLocator!=NULL) delete remoteLocator;
 		}
 
-		LinkDescriptor( const LinkDescriptor& desc ) :
-			localLink(desc.localLink),
-			localLocator(desc.localLocator),
-			remoteLink(desc.remoteLink),
-			remoteLocator(desc.remoteLocator),
-			remoteEndpoint(desc.remoteEndpoint),
-			linkup(desc.linkup) {
+		/// returns true if this is the UNSPECIFIED object
+		bool isUnspecified() const {
+			return this == &UNSPECIFIED;
 		}
 
-		bool isUnspecified() const {
-			return (this == &UNSPECIFIED);
-		}
-
-		LinkID 					localLink;
-		const NetworkLocator* 	localLocator;
-		LinkID 					remoteLink;
-		const NetworkLocator* 	remoteLocator;
-		EndpointDescriptor 		remoteEndpoint;
-
-		bool 					linkup;
+		/// link identifiers
+		LinkID localLink;
+		LinkID remoteLink;
+
+		/// used underlay addresses for the link
+		const address_v* localLocator;
+		const address_v* remoteLocator;
+
+		/// the remote end-point descriptor
+		EndpointDescriptor remoteEndpoint;
+
+		/// flag, whether this link is up
+		bool up;
 	};
 
-	/**
-	 * 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
-	 */
+	/// Link management: list of links
+	typedef vector<LinkDescriptor*> LinkSet;
+
+	/// Link management: the set of currently managed links
 	LinkSet linkSet;
 
-	/**
-	 * The message receiver
-	 */
-	MessageReceiver* messageReceiver;
-
-	/**
-	 * The local end-point descriptor
-	 */
+	/// 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
 	EndpointDescriptor localDescriptor;
 
-	/**
-	 * 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
-	 */
+	/// network change detector
 	NetworkChangeDetection networkMonitor;
 #endif
-
-	/**
-	 * The local listen port
-	 */
-	uint16_t listenport;
-
+	/// event listener
 	typedef set<CommunicationEvents*> EventListenerSet;
 	EventListenerSet eventListener;
 
+	/// sequence numbers
 	seqnum_t currentSeqnum;
 
-	/**
-	 * state of the base communication
-	 */
-	bool basecommStarted;
+	/// transport peer
+	transport_peer* transport;
+
+	/// the base overlay message receiver
+	MessageReceiver* messageReceiver;
+
+	/// convenience: send message to peer
+	void send( Message* message, const EndpointDescriptor& endpoint );
+	void send( Message* message, const LinkDescriptor& descriptor );
+
+	/// state of the base communication
+	bool started;
 
 };
@@ -352,3 +304,3 @@
 }} // namespace ariba, communication
 
-#endif /*BASECOMMUNICATION_H_*/
+#endif /* BASECOMMUNICATION_H_ */
