NetLayer.java 5.09 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
 *
 * This file is part of PeerfactSim.KOM.
 * 
 * PeerfactSim.KOM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * PeerfactSim.KOM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with PeerfactSim.KOM.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


22
23
24

package de.tud.kom.p2psim.api.network;

25
26
27
28
29
30
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.network.routing.RoutingAlgorithm;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.component.network.Bandwidth;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;

/**
 * The NetLayer provides a general interface to encapsulate various networking
 * models. This way, it is possible to use network solutions with different
 * abstraction levels and complexity. For instance, one can choose either
 * between a lightweight simple implementation which offers an adequate model
 * with minimum demands in resource requirements and a more complex
 * implementation capable to model fairshare bandwidth allocation of TCP but
 * having a lot of CPU consumption.
 * 
 * @author Sebastian Kaune
 * @author Konstantin Pussep
 * @version 3.0, 11/29/2007
 * 
 */

48
49
50
51
52
53
public interface NetLayer extends NetInterface {

	/**
	 * 
	 * @return
	 */
54
55
	public SimHost getHost();

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
	/**
	 * 
	 * Deliver a message with the given data to the destination using the given
	 * network protocol such as IPv4. The {@link NetProtocol} defines the
	 * {@link RoutingAlgorithm} that is used if the NetLayer is actually
	 * performing routing. This in turn defines the communication interface that
	 * is used on the LinkLayer to dispatch a message.
	 * 
	 * 
	 * @param msg
	 *            the msg to be sent
	 * @param receiver
	 *            the remote receiver
	 * @param protocol
	 *            the used network protocol
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	 */
	public void send(Message msg, NetID receiver, NetProtocol protocol);

	/**
	 * Returns whether the network layer has connectivity to the physical
	 * network.
	 * 
	 * @return return true if the network layer has connectivity to the physical
	 *         network
	 */
	public boolean isOnline();

	/**
	 * Returns whether the network layer has connectivity to the physical
	 * network.
	 * 
	 * @return return true if the network layer does not have connectivity to
	 *         the physical network
	 */
	public boolean isOffline();

	/**
	 * Returns the NetID of a NetLayer instance
	 * 
	 * @return the NetID of a given NetLayer instance
	 */
	public NetID getNetID();

	/**
	 * Establishes the connection to the physical network. Further to this, if
	 * installed, the correspondent ConnectivityListener will be informed about
	 * the changes in connectivity.
	 * 
	 */
	public void goOnline();

	/**
	 * Releases the connection to the physical network. Further to this, if
	 * installed, the correspondent ConnectivityListener will be informed about
	 * the changes in connectivity.
	 * 
	 */
113
114
115
116
117
118
119
120
121
122
123
124
	public void goOffline();

	/**
	 * <b>Within your Overlay and/or Application, please use
	 * host.getProperties.getPosition() instead of the NetLayer!</b>
	 * 
	 * Returns the NetPosition of a host which might be represented as the
	 * position in a two-dimensional Euclidean space, as n-dimensional
	 * coordinates used in Global Network Positioning or the location on Earth
	 * which is described by two numbers--its latitude and its longitude.
	 * 
	 * @return Position the appropriate position
125
126
	 */
	public Location getNetPosition();
127
128
129
130
131
132
133

	/**
	 * Returns the maximum physical bandwidth that is available at the given
	 * network wrapper. Thus, this value represents a state in which all upload
	 * and download connections are closed.
	 * 
	 * @return
134
135
	 */
	public Bandwidth getMaxBandwidth();
136
137
138
139
140
141
142
	
	/**
	 * Returns the current available download bandwidth of the network layer as
	 * the maximum bandwidth might be shared between concurrently established
	 * connections.
	 * 
	 * @return the available download bandwidth
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	 */
	public Bandwidth getCurrentBandwidth();
	
	/**
	 * Adds the given NetMessageListener as a handler for incoming NetMsgEvents
	 * triggered by the NetLayer which implements the message passing from the
	 * NetLayer to a layer above.
	 * 
	 * @param listener
	 *            the listener for network events
	 */
	public void addNetMsgListener(NetMessageListener listener);

	/**
	 * Removes the given NetMessageListener which handles incoming NetMsgEvents
	 * 
	 * @param listener
	 *            the listener for network events
	 */
162
	public void removeNetMsgListener(NetMessageListener listener);
163
164

}