|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectuk.org.arlott.simon.hw.f24.lbsta.Network
public class Network
Network object containing all the LANs, hosts and bridges on the network. Handles adding/removing components and one simulation iteration.
| Field Summary | |
|---|---|
private java.util.HashMap<java.awt.Point,java.util.HashSet<BridgePort>> |
bridgePortsIdx
Index of bridge ports on the network. |
private java.util.HashSet<Bridge> |
bridges
Bridges on the network. |
private java.util.HashMap<java.awt.Point,java.util.HashSet<Bridge>> |
bridgesIdx
Index of bridges on the network. |
private java.util.Vector<NetworkEvent> |
events
Events that were recoreded on the network. |
private java.util.HashSet<Host> |
hosts
Hosts on the network. |
private java.util.HashMap<java.awt.Point,Host> |
hostsHIdx
Index of horizontal hosts on the network. |
private java.util.HashMap<java.awt.Point,Host> |
hostsVIdx
Index of vertical hosts on the network. |
private java.util.HashSet<LAN> |
lans
LANs on the network. |
private java.util.HashMap<java.awt.Point,LAN> |
lansHIdx
Index of horizontal LANs on the network. |
private java.util.HashMap<java.awt.Point,LAN> |
lansVIdx
Index of vertical LANs on the network. |
private java.util.HashSet<NetworkChangeListener> |
listeners
Listeners of network objects being changed. |
private java.util.HashSet<Packet> |
newPackets
New packets to be added to the network. |
private java.lang.Long |
now
Current network simulation time. |
private java.util.HashSet<Packet> |
packets
Packets on the network. |
private java.lang.Boolean |
saved
Saved status of the network and script. |
| Constructor Summary | |
|---|---|
Network()
|
|
| Method Summary | |
|---|---|
boolean |
add(Bridge obj)
Adds a bridge to the network. |
boolean |
add(Bridge obj,
boolean test)
Adds a bridge to the network. |
boolean |
add(Host obj)
Adds a host to the network. |
boolean |
add(Host obj,
boolean test)
Adds a host to the network. |
boolean |
add(LAN obj)
Adds a LAN to the network. |
boolean |
add(LAN obj,
boolean test)
Adds a LAN to the network. |
void |
addChangeListener(NetworkChangeListener ncl)
Adds a change listener to those requiring updates of changes to network components. |
void |
addPacket(Packet packet)
Adds a packet to the network. |
private static boolean |
detectLoop(java.util.HashMap<java.awt.Point,java.util.HashSet<LAN>> checkSet)
Detects loops of LANs. |
private static boolean |
detectLoop(java.util.HashMap<java.awt.Point,java.util.HashSet<LAN>> checkSet,
java.util.HashSet<LAN> seenSet,
LAN parent,
LAN current)
Detects loops of LANs. |
void |
event(NetworkEvent event)
Adds a new event to the list of events that have occured. |
java.util.Vector<Bridge> |
getBridges()
Gets the bridges on the network. |
LAN |
getHLAN(java.awt.Point p)
Gets the horizontal LAN at a given point. |
java.util.Vector<Host> |
getHosts()
Gets the hosts on the network. |
java.util.Vector<LAN> |
getLANs()
Gets the LANs on the network. |
java.lang.Object |
getObjectAt(java.awt.Point p)
Tries to find a component at a given point. |
long |
getTime()
Gets the current network simulation time. |
LAN |
getVLAN(java.awt.Point p)
Gets the vertical LAN at a given point. |
boolean |
isSaved()
Gets the save state of the network. |
private void |
linkBridgePorts(BridgePort b)
Links any bridge ports at the same location to a BridgePort |
private void |
linkBridgePorts(LAN l,
int x,
int y)
Links any bridge ports at the given position to a LAN |
void |
markSaved()
Marks the network as being saved. |
void |
networkChanged()
Marks the network as being changed (not saved). |
void |
notifyListeners(java.lang.Object o)
Notifies the current change listeners of a change to a network component. |
private static void |
putCheckSet(java.util.HashMap<java.awt.Point,java.util.HashSet<LAN>> checkSet,
LAN l)
Put l into checkSet for loop detection |
private void |
queuePacket(java.lang.Object source,
PacketDestination destination,
PacketTransport location,
int direction,
PacketData data)
Queues a packet to be added to the network. |
private void |
queuePacket(java.util.Vector<Packet> packets,
java.lang.Object source)
Queues packets to be added to the network. |
private void |
reconnectLANs(LAN a,
LAN b)
Reconnect two LANs together when a dividing LAN has been removed. |
boolean |
remove(Bridge obj)
Removes a bridge from the network. |
boolean |
remove(Host obj,
boolean disconnect)
Removes a Host from the network. |
boolean |
remove(LAN obj,
boolean disconnect)
Removes a LAN from the network. |
void |
removeAll(Script script)
Removes all the network components and resets the script. |
void |
removeAllPackets()
Removes all the packets from the network components. |
void |
removeChangeListener(NetworkChangeListener ncl)
Removes a change listener from those requiring updates of changes to network components. |
java.util.Vector<NetworkEvent> |
run()
Performs one network simulation iteration. |
void |
setTime(long time)
Sets the current network simulation time. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final java.util.HashSet<NetworkChangeListener> listeners
private java.util.HashSet<LAN> lans
private java.util.HashMap<java.awt.Point,LAN> lansHIdx
private java.util.HashMap<java.awt.Point,LAN> lansVIdx
private java.util.HashSet<Host> hosts
private java.util.HashMap<java.awt.Point,Host> hostsHIdx
private java.util.HashMap<java.awt.Point,Host> hostsVIdx
private java.util.HashSet<Bridge> bridges
private java.util.HashMap<java.awt.Point,java.util.HashSet<Bridge>> bridgesIdx
private java.util.HashMap<java.awt.Point,java.util.HashSet<BridgePort>> bridgePortsIdx
private java.util.HashSet<Packet> packets
private java.util.HashSet<Packet> newPackets
private final java.util.Vector<NetworkEvent> events
private java.lang.Boolean saved
private java.lang.Long now
| Constructor Detail |
|---|
public Network()
| Method Detail |
|---|
public java.util.Vector<LAN> getLANs()
public LAN getHLAN(java.awt.Point p)
p - The position to check for a LAN.
LAN if found.public LAN getVLAN(java.awt.Point p)
p - The position to check for a LAN.
LAN if found.public java.util.Vector<Host> getHosts()
public java.util.Vector<Bridge> getBridges()
public void removeAll(Script script)
script - The Script to reset.public void removeAllPackets()
public boolean isSaved()
true if the network has not been modified since it was saved.public void markSaved()
public void networkChanged()
public long getTime()
public void setTime(long time)
time - The time in milliseconds.public java.lang.Object getObjectAt(java.awt.Point p)
p - The position to check for component.
public void addChangeListener(NetworkChangeListener ncl)
ncl - A NetworkChangeListener.public void removeChangeListener(NetworkChangeListener ncl)
ncl - A NetworkChangeListener.public void notifyListeners(java.lang.Object o)
o - The component that has been changed.
public boolean add(LAN obj)
throws LoopException,
InvalidPositionException
obj - The LAN to add.
true if successful.
LoopException - If the new LAN will cause a loop to be formed.
InvalidPositionException - If the LAN is in an invalid position.
public boolean add(LAN obj,
boolean test)
throws LoopException,
InvalidPositionException
obj - The LAN to add.test - true if the addition should be checked but not completed.
true if successful.
LoopException - If the new LAN will cause a loop to be formed.
InvalidPositionException - If the LAN is in an invalid position.
private static void putCheckSet(java.util.HashMap<java.awt.Point,java.util.HashSet<LAN>> checkSet,
LAN l)
l into checkSet for loop detection
l - LAN to addcheckSet - HashMap to add LAN toprivate static boolean detectLoop(java.util.HashMap<java.awt.Point,java.util.HashSet<LAN>> checkSet)
LANs.
checkSet - The set of LANs to be checked.
true if there is a loop.
private static boolean detectLoop(java.util.HashMap<java.awt.Point,java.util.HashSet<LAN>> checkSet,
java.util.HashSet<LAN> seenSet,
LAN parent,
LAN current)
LANs.
checkSet - The set of LANs to be checked.seenSet - The set of LANs that have been seen.parent - The previous LAN that was/is being checked.current - The current LAN being checked.
true if there is a loop.
public boolean add(Host obj)
throws InvalidPositionException,
TooManyHostsException
obj - The Host to add.
true if successful.
InvalidPositionException - If the host is in an invalid position.
TooManyHostsException - If the maximum number of hosts has been reached.
public boolean add(Host obj,
boolean test)
throws InvalidPositionException,
TooManyHostsException
obj - The Host to add.test - true if the addition should be checked but not completed.
true if successful.
InvalidPositionException - If the host is in an invalid position.
TooManyHostsException - If the maximum number of hosts has been reached.
public boolean add(Bridge obj)
throws InvalidPositionException,
TooManyBridgesException
obj - The Bridge to add.
true if successful.
InvalidPositionException - If the host is in an invalid position.
TooManyBridgesException - If the maximum number of bridges has been reached.
public boolean add(Bridge obj,
boolean test)
throws InvalidPositionException,
TooManyBridgesException
obj - The Bridge to add.test - true if the addition should be checked but not completed.
true if successful.
InvalidPositionException - If the host is in an invalid position.
TooManyBridgesException - If the maximum number of bridges has been reached.
private void linkBridgePorts(LAN l,
int x,
int y)
LAN
l - The LAN to link any found bridge ports to.x - The X co-ordinate positon to check.y - The Y co-ordinate positon to check.private void linkBridgePorts(BridgePort b)
BridgePort
b - The BridgePort to link any found bridge ports to.
public boolean remove(LAN obj,
boolean disconnect)
obj - The LAN to remove.disconnect - true if hosts should be disconnected.
true if the LAN was in the network.
private void reconnectLANs(LAN a,
LAN b)
LANs together when a dividing LAN has been removed.
a - The left/top LAN.b - The right/bottom LAN.
public boolean remove(Host obj,
boolean disconnect)
obj - The Host to remove.disconnect - true if the host should be disconnected from its LAN.
true if the host was in the network.public boolean remove(Bridge obj)
obj - The Bridge to remove.
true if the bridge was in the network.public java.util.Vector<NetworkEvent> run()
private void queuePacket(java.lang.Object source,
PacketDestination destination,
PacketTransport location,
int direction,
PacketData data)
source - Source of the packet.destination - Destination of the packet.location - Intial location of the packet.direction - Direction on the location of the packet.data - The data contained in the packet.
private void queuePacket(java.util.Vector<Packet> packets,
java.lang.Object source)
packets - Packets to be added.source - Source of the packets.public void addPacket(Packet packet)
packet - The Packet to add.public void event(NetworkEvent event)
event - The new NetworkEvent to add.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||