Here is the code and exlaintion of it.Ok hmm.. well the code is more or less what I'll sent you before.
The code is basically working excpet that sometimes it does not work and in some instances it never works.
Let me explain how the code basically works :
Ok I've alteed the code only to have a very simple menubar. The menu bar has the an "Add toolbar" button. Just click it to add the toolbar. Thats the first thing you must do.
When to toolbar appears we are only concerned with the MS, BTS and BSC
buttons. Forget the rest for the while. The rest aren't fully implemneted yet.
Ok as you know am using Discrete Event Simulation techniques to do a simulation. As you can see the MS.java , BTS.java and BSC.java files each have one event each. And each event performs a set of actions like sending out signals, analyzing signals and sending out signals based on signals sent in.
I also needed all the events to operate in parallel. This is why I execute each event in a sepearte thread. The code for execeting each event in a thread in seen close to the bottom of the Link.java file.
Oh after the simulation time is more than 600 a pair of graphs are plotted for each node. A graph from node1 to node2 and another from node2 to node1. However the after the simulation a JFrame containing buttons will appear(if the simulation is sucessful). When u click a button you will get the graph for a particular node. Each button is label and will tell you which graph you will view if the button is pressed.
So heres what to do.
Add two MS to the canvas and one BTS. Connect the two MS together and then connect one( only one) MS to the BTS. And click simulate on the menubar. This works fine. The graphs appear and stuff.
Then add another BTS to the canvas and connect this BTS to the other MS.
Simulate. This works sometimes. Some of the graphs appear others don't. WHy?
Now add a BSC and connect each BTS to the it. That is we now have 5 icons on the canvas - 2 MS , 2 BTS and one BSC.
Now simulate. And u get a set of errors and no graph.
WHats going wrong?
The code is attached.
If the code does not complie let me know. And if any files are missing please let me know. Thanks.
yours respectfully Avin Sinanan
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import AbstractNetworkButton.*;
public class SimProject {
public static void main(String[] args) {
MainFrame mainframe = new MainFrame();
System.out.println(Thread.currentThread());
}
}
class MainFrame {
private JFrame frame;
private static ClickHandler clix;
private JCanvas canvas;
public GSMMenuBar menubar;
public MainFrame() {
// create main frame
clix = new ClickHandler();
canvas = new JCanvas(clix);
canvas.setLayout(null); // freely move the created buttons
clix.setCanvas(canvas);
frame = new JFrame("Program Main Window");
frame.addMouseListener(clix); // for stopping a connecting-process
GSMToolBar gsmToolBar = new GSMToolBar(MainFrame.this , canvas);
// set platform-dependend layout
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
// close frame with X
// tribute to an old IDE, you should stick to the following (single) LOC:
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
/** in this spagehetti-code version of the program clix and
* canvas are interdependent. We cannot use the ClickHandler(aCanvas c)-
* constructor, as canvas isn't defined yet.
* So we enclose the JCanvas-setup by the ClickHandler-setup!
*/
// make the button-canvas scrollable
JScrollPane scroll = new JScrollPane(canvas);
scroll.setAutoscrolls(false);
// add the junk to the frame
menubar = new GSMMenuBar(frame, scroll,canvas,clix, gsmToolBar.gsmToolBar());
frame.setJMenuBar(menubar.gsmMenuBar());
frame.getContentPane().add(scroll);
frame.setSize(800,800);
frame.setVisible(true);
}
protected JCanvas accessCanvas() {
// we will have to get our hands on canvas in order to add buttons to it
return canvas;
}
protected ClickHandler getClickHandler() {
return clix;
}
}
/*-------------------------------------------------------*/
class JCanvas extends JComponent {
ClickHandler clix;
public JCanvas(ClickHandler clix) {
setDoubleBuffered(true);
setOpaque(true);
this.clix = clix;
}
public void paintComponent(Graphics g) {
// fill entire component white
g.setColor(Color.white);
g.fillRect(0,0,getWidth(),getHeight());
// reset Graphics-color
g.setColor(Color.black);
/**
* In the following LOC the connections are drawn.
* The matrix is a square-matrix. The vector's size is always less than or
* equal to the matrix' base-length. As we only need to run through
* connected buttons we take the vector's size as indeces for the inner
* and for the outer loop.
* The adjacency-matrix' indices correspond to the Button-Vectors
* element-positions. So we can retrieve the connected buttons
* by using the vector's elementAt(int i)-method.
* The lines start and end in the middle of the button. As the buttons
* will be drawn in the paintChildren-method of the JComponent-class
* (our JCanvas) and as paintChildren is called after paintComponent
* was called, the buttons will cover the lines where needed.
*/
//Vector = clix.getButtonVector();
Global.v = clix.getButtonVector();
//boolean[][] aMatrix = clix.getAdjacencyMatrix();
Global.aMatrix = clix.getAdjacencyMatrix();
int baseLength = Global.v.size();
if(Global.openButtonIsPressed==true)
{
Global.v= Global.newButtons ;
}
for (int i = 0; i < baseLength; i++) {
for (int j = 0; j < baseLength; j++) {
if (Global.aMatrix[i][j]==true)
{
if ((i >= Global.v.size()) || (j >= Global.v.size())) break;
JButton b1 = (JButton)Global.v.elementAt(i);
JButton b2 = (JButton)Global.v.elementAt(j);
int b1X = b1.getX() + b1.getWidth()/2;
int b1Y = b1.getY() + b1.getHeight()/2;
int b2X = b2.getX() + b2.getWidth()/2;
int b2Y = b2.getY() + b2.getHeight()/2;
g.drawLine(b1X, b1Y, b2X, b2Y);
}
}
}
super.paintComponent(g);
}
/**
* we need the following 3 methods in order to enable the scrollPane
* that holds our canvas to do its job properly
*/
public Dimension getPreferredSize() {
return new Dimension(400, 400);
}
public Dimension getMaximumSize() {
return getPreferredSize();
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
}
/*--------------------------------------------------------------------*/
class Global
{
static public int totalSize ;
static public JFrame frameOfButtons = new JFrame("PICK A PAIR OF NODES");
static public JPanel pane = new JPanel();
static public int presentLinkandLinkReverseNumber =0;
static public Vector v = new Vector();
static public Vector buttons = new Vector();
static public boolean[][] matrix ;
static public boolean openButtonIsPressed = false ;
static public Vector newButtons = new Vector();
static public Vector vectorForSim = new Vector();
static public boolean[][] matrixForSim ;
static public boolean[][] aMatrix ;
static public Graphics h;
static public boolean is41ToolBarStatus = false ;
static public boolean gsmToolBarStatus = false ;
static public JButton deleteBuffer = new JButton();
static public boolean link1Flag = false ;
static public boolean link2Flag = false ;
static public boolean flagHasBeenTripped = false ;
static public int linkNumber = 0 ;
}
/*--------------------------------------------------------------------*/
class AddButton extends Simulator{
private static int a =0;
private static int b =0;
private static int c =0;
private static int d =0;
private static int e =0;
private static int f =0;
private static int g =0;
private static int h =0;
private static int j =0;
private static int k =0;
/**
* class to create new Buttons and add them to a canvas in a static method.
* No instances are supposed to be created from that class
*/
private AddButton() {}
public static JButton addButton(MainFrame aFrame, String s) {
/**
* The method returns a NetworkButton depending on the String
* passed with a reference to the frame's
* clickHandler. The ClickHandler takes care of all the user
* input. So there must only be a single (static) instance
* used for the whole program
*/
if (s.equals("MS"))
{
a++;
ImageIcon icon = new ImageIcon("MS.gif");
MS ms = new MS("", a,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(ms);
return ms.msButtonMethod();
}
if (s.equals("BTS"))
{
b++;
ImageIcon icon = new ImageIcon("BTS.gif");
BTS bts = new BTS("", b,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(bts);
return bts.btsButtonMethod();
}
if (s.equals("BSC"))
{
c++;
ImageIcon icon = new ImageIcon("BSC.gif");
BSC bsc = new BSC("", c,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(bsc);
return bsc.bscButtonMethod();
}
if (s.equals("MSC"))
{
d++;
ImageIcon icon = new ImageIcon("MSC.gif");
MSC msc = new MSC("", d,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(msc);
return msc.mscButtonMethod();
}
if (s.equals("HLR"))
{
e++;
ImageIcon icon = new ImageIcon("HLR.gif");
HLR hlr = new HLR("", e,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(hlr);
return hlr.hlrButtonMethod();
}
if (s.equals("VLR"))
{
f++;
ImageIcon icon = new ImageIcon("VLR.gif");
VLR vlr = new VLR("", f,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(vlr);
return vlr.vlrButtonMethod();
}
if (s.equals("GMSC"))
{
g++;
ImageIcon icon = new ImageIcon("GMSC.gif");
GMSC gmsc = new GMSC("", g,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(gmsc);
return gmsc.gmscButtonMethod();
}
if (s.equals("PSTN"))
{
h++;
ImageIcon icon = new ImageIcon("PSTN.gif");
PSTN pstn = new PSTN("", h,icon, aFrame.getClickHandler()) ;
Global.vectorForSim.add(pstn);
return pstn.pstnButtonMethod();
}
return null;
}
}
/*------------------------------------------------------------------*/
class ClickHandler extends MouseAdapter implements MouseMotionListener {
private JCanvas canvas; // the canvas to draw on
//private Vector buttons; // vector to dynamically store the buttons
private static int size; // array-size - will be dynamically increased
//private boolean[][] matrix; // adjacency-matrix
private int xOffset; // cursor-offset for mouseDragged()-method
private int yOffset;
private static JButton lastButton; // buffer used to connect 2 buttons
private boolean isLeftPressed; // buffers pressed mouse-Button
private boolean isRightPressed; // ditto
ClickHandler() {
this(null);
}
ClickHandler(JCanvas aCanvas) {
canvas = aCanvas;
size = 10;
Global.buttons = new Vector();
Global.matrix = new boolean[100][100];
lastButton = new JButton();
}
protected void setCanvas(JCanvas aCanvas) {
/**
* as the ClickHandler holds a reference to the canvas and the canvas
* in reverse holds a reference to the ClickHandler using the constructors
* with the canvas-parameter without having the canvas constructed or using
* the click-paramter without having having the ClickHandler constructed
* would result in an error, as neither one could be resolved. So we
* have to create the ClickHandler with the parameterless constructor
* and set its canvas later.
*/
canvas = aCanvas;
}
private void connectButtons(JButton b1, JButton b2) {
/**
* the method sets the values of a boolean matrix (adjacency-matrix)
* that represents the connections. The matrix' size will be increased
* whenever needed. Every button is stored in a Vector once it
* was double-clicked with the left mouse-button (see mouseClicked()).
* The array-indeces are used in the canvas' paintComponent-method
* to address the button-vector-elements (JButtons). The JButtons
* are then used to (dynamically) get the coordinates to draw the
* connections (lines). The only error-checking involved is a
* ring-connection from one button to the same button. Any other
* error-checking is ommitted, since only pressed buttons will be
* passed as parameters (check clickCount()=? for details)
* The method also <b>disconnects</b> buttons, if they were already
* connected!
*/
if(Global.openButtonIsPressed==true)
{
Global.buttons = Global.newButtons ;
}
if (b1 == b2) return; // error-checking: test for same object
//if (((AbstractNetworkButton)b1).isConnectionAllowed(b2)) {
int leftIndex = Global.buttons.indexOf(b1);
int rightIndex = Global.buttons.indexOf(b2);
// increase array-size dynamically (we do it by hand, just for fun)
if ((leftIndex == size) || (rightIndex == size)) {
size =size + 10;
int maxIndex = size;
boolean[][] buffy = Global.matrix;
Global.matrix = new boolean[maxIndex][maxIndex];
for (int i = 0; i < maxIndex; i++) {
for (int j = 0; j < maxIndex; j++) {
Global.matrix[i][j] = buffy[i][j];
}
}
}
// set adjacency-matrix
Global.matrix[leftIndex][rightIndex] = !Global.matrix[leftIndex][rightIndex];
// as it is an undirected graph: do it backwards, too
//Global.matrix[rightIndex][leftIndex] = !Global.matrix[rightIndex][leftIndex];
//}
//else
//{
//JOptionPane.showMessageDialog(canvas, "Cannot connect these two");
//}
}
public boolean[][] getAdjacencyMatrix() {
Global.matrixForSim = Global.matrix ;
return Global.matrix;
}
public Vector getButtonVector() {
return Global.buttons;
}
public void mousePressed(MouseEvent me) {
if (me.getSource() instanceof JButton) {
// store mouse-position as offset for button-dragging
xOffset = me.getX();
yOffset = me.getY();
// add pressed button to button-vector if not already included
if (Global.buttons.indexOf(me.getSource()) == -1) {
Global.buttons.add(me.getSource());
}
}
if (me.getModifiers() == MouseEvent.BUTTON1_MASK) {
isLeftPressed = true;
}
if (me.getModifiers() == MouseEvent.BUTTON3_MASK) {
isRightPressed = true;
}
}
public void mouseReleased(MouseEvent me) {
}
public void mouseClicked(MouseEvent me) {
/**
* reaction to mouseClicked depends mainly on the active cursor-type
* so be sure to always reset the cursor-type to default when you're
* done with a specific (re-)action
*/
if (((me.getModifiers() == MouseEvent.BUTTON1_MASK) && (isRightPressed)) ||
((me.getModifiers() == MouseEvent.BUTTON3_MASK) && (isLeftPressed))) {
/**
* connecting-process was cancelled
*/
canvas.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
isRightPressed = false;
isLeftPressed = false;
return;
}
/**
* react on left single-click
*/
if (me.getSource() instanceof JButton) {
if ((me.getClickCount() == 1) &&
(me.getModifiers() == MouseEvent.BUTTON1_MASK)) {
if (canvas.getCursor().getType() == Cursor.CROSSHAIR_CURSOR) {
connectButtons(lastButton, (JButton)me.getSource());
// paint the lines
canvas.repaint();
// reset cursor
canvas.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
//store in buttonBuffer
Global.deleteBuffer = (JButton)me.getSource() ;
}
/**
* react on left double-click
*/
if ((me.getClickCount() == 2) &&
(me.getModifiers() == MouseEvent.BUTTON1_MASK)) {
// change Cursor
canvas.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
// buffer the last button for later use in connectButtons
lastButton = (JButton)me.getSource();
}
}
// reset pressed-buffers
isLeftPressed = false;
isRightPressed = false;
}
public void mouseMoved(MouseEvent me) {}
public void mouseDragged(MouseEvent mee) {
if (mee.getComponent() instanceof JButton) {
/**
* move the button, don't let it exceed the canvas' bounds,
* offsets are calculated when mouse-button is pressed
*/
JButton b = (JButton)mee.getComponent();
int x = b.getX() + mee.getX() - xOffset;
if (x + b.getWidth() > canvas.getWidth()) {
x = canvas.getWidth() - b.getWidth();
}
if (x < 0) x = 0;
int y = b.getY() + mee.getY() - yOffset;
if (y + b.getHeight() > canvas.getHeight()) {
y = canvas.getHeight() - b.getHeight();
}
if (y < 0) y = 0;
b.setLocation(x, y);
// paint the lines
canvas.repaint();
}
}
}
/*----------------------------------------------*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import javax.swing.filechooser.*;
import java.io.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.io.*;
import java.util.zip.*;
import java.util.Vector;
import java.util.Properties;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
class GSMMenuBar extends Simulator
{
JFrame frame;
JScrollPane scroll ;
JCanvas canvas ;
ClickHandler clix ;
JToolBar theGSMToolBar ;
Link link1 ;
Link link2 ;
double newTime=0 ;
MS ms = new MS();
BTS bts = new BTS();
BSC bsc = new BSC();
MSC msc = new MSC();
HLR hlr = new HLR();
VLR vlr = new VLR();
GMSC gmsc = new GMSC();
PSTN pstn = new PSTN();
public GSMMenuBar(JFrame frameEx , JScrollPane scrollEx , JCanvas canvasEx, ClickHandler clixEx, JToolBar gsmToolBarEx)
{
frame = frameEx;
scroll = scrollEx;
canvas = canvasEx ;
clix = clixEx ;
theGSMToolBar = gsmToolBarEx ;
}
public JMenuBar gsmMenuBar()
{
JMenuBar menubar = new JMenuBar() ;
//Make menu options
JMenu file = new JMenu("File");
JMenu addToolBar = new JMenu("Add Tool Bar");
JMenu simulate = new JMenu("Simulate");
//Add items to file option
file.setMnemonic(KeyEvent.VK_I);
file.getAccessibleContext().setAccessibleDescription("");
JMenuItem open = new JMenuItem("Open", new ImageIcon("OPEN.gif"));
open.setMnemonic(KeyEvent.VK_D);
open.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Global.openButtonIsPressed = true ;
OpenClass open =new OpenClass(frame , scroll , canvas , clix);
}
});
file.add(open);
JMenuItem save = new JMenuItem("Save", new ImageIcon("SAVE.gif"));
save.setMnemonic(KeyEvent.VK_D);
save.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
SaveClass save =new SaveClass(frame);
}
});
file.add(save);
addToolBar.setMnemonic(KeyEvent.VK_I);
addToolBar.getAccessibleContext().setAccessibleDescription("");
JMenuItem gsmToolBar = new JMenuItem("GSM Tool Bar", new ImageIcon("GSM.gif"));
gsmToolBar.setMnemonic(KeyEvent.VK_D);
gsmToolBar.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
frame.getContentPane().add("North", theGSMToolBar);
frame.setVisible(true);
}
});
addToolBar.add(gsmToolBar);
//Add items to Simulate Option
simulate.setMnemonic(KeyEvent.VK_I);
simulate.getAccessibleContext().setAccessibleDescription("");
JMenuItem sim = new JMenuItem("Start Simulation", new ImageIcon("GSM.gif"));
sim.setMnemonic(KeyEvent.VK_D);
sim.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Global.aMatrix = clix.getAdjacencyMatrix();
events = new ListQueue();
int baseLength = Global.v.size();
for (int i = 0; i < baseLength; i++) {
for (int j = 0; j < baseLength; j++) {
if (Global.aMatrix[i][j]) {
link1 = new Link();
link2 = new Link();
Global.linkNumber++ ;
newTime = newTime + 1.0 ;
/*Set Flags to False*/
Global.link1Flag = false ;
Global.link2Flag = false ;
/* All the i's start here */
/*------------------------------------------------------------------------*/
if (Global.vectorForSim.elementAt(i) instanceof MS)
{
ms = (MS)Global.vectorForSim.elementAt(i);
ms.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
ms.linkSender[Global.linkNumber] = link1;
ms.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
ms.linkSender[Global.linkNumber] = link2;
ms.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime ;
link2.time = newTime+0.1;
ms.time = newTime+0.2;
insert(link1);
insert(link2);
insert(ms) ;
}
if (Global.vectorForSim.elementAt(i) instanceof BTS)
{
bts = (BTS)Global.vectorForSim.elementAt(i);
bts.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
bts.linkSender[Global.linkNumber] = link1;
bts.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
bts.linkSender[Global.linkNumber] = link2;
bts.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime+0.1;
bts.time = newTime+0.2;
insert(link1);
insert(link2);
insert(bts) ;
}
if (Global.vectorForSim.elementAt(i) instanceof BSC)
{
bsc = (BSC)Global.vectorForSim.elementAt(i);
bsc.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
bsc.linkSender[Global.linkNumber] = link1;
bsc.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
bsc.linkSender[Global.linkNumber] = link2;
bsc.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime+0.1;
bsc.time = newTime+0.2;
insert(link1);
insert(link2);
insert(bsc) ;
}
if (Global.vectorForSim.elementAt(i) instanceof MSC)
{
msc = (MSC)Global.vectorForSim.elementAt(i);
msc.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
msc.linkSender[Global.linkNumber] = link1;
msc.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
msc.linkSender[Global.linkNumber] = link2;
msc.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime;
msc.time = newTime;
insert(link1);
insert(link2);
insert(msc) ;
}
if (Global.vectorForSim.elementAt(i) instanceof HLR)
{
hlr = (HLR)Global.vectorForSim.elementAt(i);
hlr.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
hlr.linkSender[Global.linkNumber] = link1;
hlr.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
hlr.linkSender[Global.linkNumber] = link2;
hlr.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime;
hlr.time = newTime;
insert(link1);
insert(link2);
insert(hlr) ;
}
if (Global.vectorForSim.elementAt(i) instanceof VLR)
{
vlr = (VLR)Global.vectorForSim.elementAt(i);
vlr.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
vlr.linkSender[Global.linkNumber] = link1;
vlr.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
vlr.linkSender[Global.linkNumber] = link2;
vlr.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime;
vlr.time = newTime;
insert(link1);
insert(link2);
insert(vlr) ;
}
if (Global.vectorForSim.elementAt(i) instanceof GMSC)
{
gmsc = (GMSC)Global.vectorForSim.elementAt(i);
gmsc.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
gmsc.linkSender[Global.linkNumber] = link1;
gmsc.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
gmsc.linkSender[Global.linkNumber] = link2;
gmsc.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime;
gmsc.time = newTime;
insert(link1);
insert(link2);
insert(gmsc) ;
}
if (Global.vectorForSim.elementAt(i) instanceof PSTN)
{
pstn = (PSTN)Global.vectorForSim.elementAt(i);
pstn.receiveLink(link1 , link2);
if(Global.link1Flag== true)
{
pstn.linkSender[Global.linkNumber] = link1;
pstn.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
pstn.linkSender[Global.linkNumber] = link2;
pstn.linkProcessor[Global.linkNumber] = link1;
}
link1.time = newTime;
link2.time = newTime;
pstn.time = newTime;
insert(link1);
insert(link2);
insert(pstn) ;
}
/* All the i's start here */
/*------------------------------------------------------------------------*/
if (Global.vectorForSim.elementAt(j) instanceof MS)
{
ms = (MS)Global.vectorForSim.elementAt(j);
ms.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
ms.linkSender[Global.linkNumber] = link1;
ms.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
ms.linkSender[Global.linkNumber] = link2;
ms.linkProcessor[Global.linkNumber] = link1;
}
ms.time = newTime+0.2 ;
insert(ms) ;
}
if (Global.vectorForSim.elementAt(j) instanceof BTS)
{
bts = (BTS)Global.vectorForSim.elementAt(j);
bts.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
bts.linkSender[Global.linkNumber] = link1;
bts.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
bts.linkSender[Global.linkNumber] = link2;
bts.linkProcessor[Global.linkNumber] = link1;
}
bts.time = newTime+0.2;
insert(bts) ;
}
if (Global.vectorForSim.elementAt(j) instanceof BSC)
{
bsc = (BSC)Global.vectorForSim.elementAt(j);
bsc.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
bsc.linkSender[Global.linkNumber] = link1;
bsc.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
bsc.linkSender[Global.linkNumber] = link2;
bsc.linkProcessor[Global.linkNumber] = link1;
}
bsc.time = newTime+0.2;
insert(bsc) ;
}
if (Global.vectorForSim.elementAt(j) instanceof MSC)
{
msc = (MSC)Global.vectorForSim.elementAt(j);
msc.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
msc.linkSender[Global.linkNumber] = link1;
msc.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
msc.linkSender[Global.linkNumber] = link2;
msc.linkProcessor[Global.linkNumber] = link1;
}
msc.time = newTime ;
insert(msc) ;
}
if (Global.vectorForSim.elementAt(j) instanceof HLR)
{
hlr = (HLR)Global.vectorForSim.elementAt(j);
hlr.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
hlr.linkSender[Global.linkNumber] = link1;
hlr.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
hlr.linkSender[Global.linkNumber] = link2;
hlr.linkProcessor[Global.linkNumber] = link1;
}
hlr.time = newTime ;
insert(hlr) ;
}
if (Global.vectorForSim.elementAt(j) instanceof VLR)
{
vlr = (VLR)Global.vectorForSim.elementAt(j);
vlr.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
vlr.linkSender[Global.linkNumber] = link1;
vlr.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
vlr.linkSender[Global.linkNumber] = link2;
vlr.linkProcessor[Global.linkNumber] = link1;
}
vlr.time = newTime ;
insert(vlr) ;
}
if (Global.vectorForSim.elementAt(j) instanceof GMSC)
{
gmsc = (GMSC)Global.vectorForSim.elementAt(j);
gmsc.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
gmsc.linkSender[Global.linkNumber] = link1;
gmsc.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
gmsc.linkSender[Global.linkNumber] = link2;
gmsc.linkProcessor[Global.linkNumber] = link1;
}
gmsc.time = newTime ;
insert(gmsc) ;
}
if (Global.vectorForSim.elementAt(j) instanceof PSTN)
{
pstn = (PSTN)Global.vectorForSim.elementAt(j);
pstn.receiveLink(link1 , link2);
if( Global.flagHasBeenTripped == true)
{
Global.link1Flag = false;
}
if(Global.link1Flag == true)
{
pstn.linkSender[Global.linkNumber] = link1;
pstn.linkProcessor[Global.linkNumber] = link2;
}
if(Global.link1Flag == false)
{
pstn.linkSender[Global.linkNumber] = link2;
pstn.linkProcessor[Global.linkNumber] = link1;
}
pstn.time = newTime ;
insert(pstn) ;
}
}
}
}
doAllEvents();
}
});
simulate.add(sim);
menubar.add(file);
menubar.add(addToolBar);
menubar.add(simulate);
return menubar ;
}
}
/*---------------------OPEN CLASS TO VIEW HARDDRIVE CLASS-----*/
class OpenClass
{
JFrame frame;
JScrollPane scroll ;
JCanvas canvas ;
ClickHandler clix ;
public OpenClass(JFrame frameEx , JScrollPane scrollEx , JCanvas canvas , ClickHandler clixEx)
{
frame = frameEx ;
scroll = scrollEx;
this.canvas = canvas ;
clix = clixEx ;
FileDialog f = new FileDialog(frame, "Load Scribble", FileDialog.LOAD);
f.show(); // Display the dialog and block.
String filename = f.getFile(); // Get the user's response
if (filename != null) { // If user didn't click "Cancel".
try {
// Create necessary input streams
FileInputStream fis = new FileInputStream(filename); // Read from file
GZIPInputStream gzis = new GZIPInputStream(fis); // Uncompress
ObjectInputStream in = new ObjectInputStream(gzis); // Read objects
// Read in an object. It should be a vector of scribbles
Global.newButtons = (Vector)in.readObject();
in.close(); // Close the stream.
canvas.removeAll();
//canvas.repaint();
//canvas.setVisible(true);
for( int i = 0; i < Global.newButtons.size(); ++i )
{
((JButton)Global.newButtons.elementAt(i)).addMouseMotionListener(clix);
((JButton)Global.newButtons.elementAt(i)).addMouseListener(clix);
canvas.add( (JButton)Global.newButtons.elementAt( i ));
}
}
// Print out exceptions. We should really display them in a dialog...
catch (Exception e) { System.out.println(e); }
}
}
}
/*-------------------Save Class to view hardrive--------*/
class SaveClass
{
JFrame frame ;
public SaveClass(JFrame frameEx )
{
frame = frameEx ;
FileDialog f = new FileDialog(frame, "Save Scribble", FileDialog.SAVE);
f.show(); // Display the dialog and block.
String filename = f.getFile(); // Get the user's response
if (filename != null) { // If user didn't click "Cancel".
try {
// Create the necessary output streams to save the scribble.
FileOutputStream fos = new FileOutputStream(filename); // Save to file
GZIPOutputStream gzos = new GZIPOutputStream(fos); // Compressed
ObjectOutputStream out = new ObjectOutputStream(gzos); // Save objects
out.writeObject(Global.v); // Write the entire Vector of scribbles
out.flush(); // Always flush the output.
out.close(); // And close the stream.
}
// Print out exceptions. We should really display them in a dialog...
catch (IOException e) { System.out.println(e); }
}
}
}
[java]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import AbstractNetworkButton.*;
class GSMToolBar
{
public MainFrame theFrame;
public JToolBar toolbar;
public JCanvas canvas ;
//MainFrame.this
public GSMToolBar(MainFrame someFrame , JCanvas aCanvas )
{
theFrame = someFrame;
canvas = aCanvas ;
}
public JToolBar gsmToolBar()
{
// create toolbar
toolbar = new JToolBar(JToolBar.HORIZONTAL);
JButton ms = new JButton ("MS");
ms.setMnemonic(KeyEvent.VK_M);
ms.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "MS"));
canvas.repaint();
}
});
toolbar.add(ms);
toolbar.addSeparator();
JButton bts = new JButton ("BTS");
bts.setMnemonic(KeyEvent.VK_B);
bts.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "BTS"));
canvas.repaint();
}
});
toolbar.add(bts);
toolbar.addSeparator();
// just to indicate that we would need more entities.
JButton bsc = new JButton("BSC");
bsc.setMnemonic(KeyEvent.VK_S);
bsc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "BSC"));
canvas.repaint();
}
});
toolbar.add(bsc);
toolbar.addSeparator();
JButton msc = new JButton("MSC");
msc.setMnemonic(KeyEvent.VK_M);
msc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "MSC"));
canvas.repaint();
}
});
toolbar.add(msc);
toolbar.addSeparator();
JButton hlr = new JButton("HLR");
hlr.setMnemonic(KeyEvent.VK_M);
hlr.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "HLR"));
canvas.repaint();
}
});
toolbar.add(hlr);
toolbar.addSeparator();
JButton gmsc = new JButton("GMSC");
gmsc.setMnemonic(KeyEvent.VK_M);
gmsc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "GMSC"));
canvas.repaint();
}
});
toolbar.add(gmsc);
toolbar.addSeparator();
JButton vlr = new JButton("VLR");
vlr.setMnemonic(KeyEvent.VK_M);
vlr.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "VLR"));
canvas.repaint();
}
});
toolbar.add(vlr);
toolbar.addSeparator();
JButton pstn = new JButton("PSTN");
pstn.setMnemonic(KeyEvent.VK_M);
pstn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
canvas.add(AddButton.addButton(theFrame, "PSTN"));
canvas.repaint();
}
});
toolbar.add(pstn);
toolbar.addSeparator();
//NEW STUFF WILL BE ADDED HERE
JButton delete = new JButton("Delete");
delete.setMnemonic(KeyEvent.VK_M);
delete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//Write what happend here when delete button is pressed!!!!!!!
//Global.newButtons.remove(Global.deleteBuffer);
int removeElement = Global.v.indexOf(Global.deleteBuffer);
int vectorLenght = Global.v.size();
for(int y = 0 ; y < vectorLenght ; y++)
{
System.out.println("Am in the for *************** loop");
Global.aMatrix[y][removeElement] = false;
Global.aMatrix[removeElement][y] = false;
}
canvas.remove(Global.deleteBuffer);
canvas.repaint();
}
});
toolbar.add(delete);
toolbar.addSeparator();
toolbar.setBackground(Color.blue);
return toolbar ;
}
}
/*------------------LINK CLASS-------------------------*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.util.Random.*;
class Link extends Event
{
static int n =0 ;
int totalBytes = 0;
double timeNow = 0 ;
double timeNowNow = 0;
double timeBelow = 0;
private int i;
private int l;
private int data[] = new int[1];
private int data1[] = new int[1];
private int k=0;
private int q=0;
private int newSize;
private int newSize1;
private String firstName;
private String lastName;
private Vector inputSignals = new Vector();
private boolean displayed = false;
private Plot plot ;
private JFrame frame ;
void execute( AbstractSimulator simulator )
{
//insert( simulator, removeFirstSignal() );
//time += Random.exponential( 1.0 );
while( ((Simulator)simulator).now() <= 610.0 )
{
System.out.print("Link time " + ((Simulator)simulator).now() );
insert( simulator, removeFirstSignal() );
simulator.insert( this );
}
}
public void firstNameOfThisLink( String firstNameEx )
{ firstName = firstNameEx;
}
//Return firstName of the Link
public String getFirstNameOfLink()
{
return firstName ;
}
public void lastNameOfThisLink( String lastNameEx )
{
lastName = lastNameEx;
}
//Return LastName of the Link
public String getLastNameOfLink()
{
return lastName ;
}
void insert( AbstractSimulator simulator, String signalEx )
{
StringBuffer dest1 = new StringBuffer(5);
String sig = signalEx ;
for(int i=8 ; i<=12 ; i++)
{
dest1.append(sig.charAt(i));
}
String signalling = dest1.toString();
int bytes = Integer.parseInt( signalling );
totalBytes = totalBytes + bytes ;
timeNow = ((Simulator)simulator).now();
if( timeNow > (timeBelow + 10) )
{
int timeNowInt = (int)timeNow;
arrayMethod1( totalBytes );
arrayMethod( timeNowInt );
System.out.println("Total bytes at this time is " + totalBytes);
System.out.println("The time is " + timeNowInt);
totalBytes = 0;
timeBelow = timeBelow + 10;
}
timeNowNow = ((Simulator)simulator).now();
if( timeNowNow > 600 && !displayed )
{
timeNow = 0;
displayGraph();
displayed = true;
}
//inputSignals.addElement( signalling );
}
int size()
{
return inputSignals.size();
}
public void addSignalToVector( String inputSignal )
{
inputSignals.addElement( inputSignal );
}
public String removeFirstSignal()
{
String signal = "NOTHINGS00090NULL000000" ;
if( inputSignals.size() == 0 )
{
signal = "NOTHINGS00000NULL000000" ;
}
if(inputSignals.size() > 0)
{
signal = (String) inputSignals.firstElement();
inputSignals.removeElementAt( 0 );
}
return signal ;
}
void arrayMethod( int j )
{
i = j ;
if( k == data.length )
{
newSize = data.length +1;
int[] newData = new int[newSize];
System.arraycopy( data, 0, newData, 0, data.length );
data = newData;
data[k] = i;
}
else
{
data[k] = i;
}
k++;
}
void arrayMethod1( int m )
{
l = m ;
if( q == data1.length )
{
newSize1 = data1.length + 1;
Global.totalSize = newSize1 ;
int[] newData1 = new int[newSize1];
System.arraycopy( data1, 0, newData1, 0, data1.length );
data1 = newData1;
data1[q] = l;
}
else
{
data1[q]=l;
}
q++;
}
/*---------------DISPLAY GRAPH METHOD ---------------------------------*/
void displayGraph()
{
dESSimGraph( data, data1, firstName, lastName );
}
public void dESSimGraph( int[] dataEx , int[] data1Ex , String name1, String name2 )
{
frame = new JFrame();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing( WindowEvent we )
{
frame.dispose();
displayed = false;
}
});
frame.setSize( 800, 750 );
plot = new Plot( dataEx , data1Ex, name1, name2 );
Global.frameOfButtons.setVisible(true);
Global.frameOfButtons.setSize(400,400);
JButton button = new JButton("" + name1 +" to " +name2) ;
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
frame.getContentPane().add( plot );
frame.setVisible( true );
}
});
Global.pane.add(button);
Global.frameOfButtons.getContentPane().add(Global.pane);
// frame.getContentPane().add( plot );
// frame.setVisible( true );
}
}
/*------------------PLOT CLASS-------------------------------*/
class Plot extends JPanel
{
int[] x ;
int[] y ;
int size = Global.totalSize ;
int[] xx = new int[size];
int[] yy = new int[size];
String xlabel, ylabel, title;
int xdim, ydim, yzero, xzero, xdraw, ydraw;
double xtic, ytic, xpoint, ypoint;
double xmax, xmin, ymax, ymin;
double x1max ;
double x1min ;
private String nameOfPlot1;
private String nameOfPlot2;
public Plot(int[] dataEx , int[] data1Ex , String nameOfPlot1Ex, String nameOfPlot2Ex)
{
System.out.println("Yep ");
x = dataEx ;
y = data1Ex ;
nameOfPlot1 = nameOfPlot1Ex;
nameOfPlot2 = nameOfPlot2Ex ;
xdim = 600;
ydim = 600;
xtic = 100;
ytic = 5000;
xlabel = ("Time");
ylabel = ("Bytes");
title = ylabel + " versus " + xlabel;
xmax = x[0];
xmin = x[0];
ymax = y[0];
ymin = y[0];
x1min= x[0];
x1max= x[0];
for (int i=0; i < size; i++){
if (x[i] > xmax) {
xmax = x[i];
}
if (x[i] < xmin) {
xmin = x[i];
}
if (y[i] > ymax) {
ymax = y[i];
x1max = x[i];
}
if (y[i] < ymin) {
ymin = y[i];
x1min = x[i];
}
}
//xx and yy are the scaled x and y used for plotting
for (int i=0; i < size; i++){
xx[i] = (int) (50 + (((x[i]-xmin)/(xmax-xmin)) * (xdim-100)));
yy[i] = (int) ((ydim - 50) - (((y[i]-ymin)/(ymax-ymin)) * (ydim-100)));
}
//Find Zero point on y-axis required for drawing the axes
if ((ymax*ymin) < 0){
yzero = (int) ((ydim - 50) - (((0-ymin)/(ymax-ymin)) * (ydim-100)));
}
else{
yzero = (int) ((ydim - 50) - ((0/(ymax-ymin)) * (ydim-100)));
}
//Find zero point on x-axis required for drawing the axes
if ((xmax*xmin) < 0) {
xzero = (int) (50 + (((0-xmin)/(xmax-xmin)) * (xdim-100)));
}
else{
xzero = (int) (50 + ((0/(xmax-xmin)) * (xdim-100)));
}
//Now ready to plot the results
repaint();
}
public void paint(Graphics g){
Font f1 = new Font("TimesRoman", Font.PLAIN, 10);
g.setFont(f1);
//First draw the axes
//y-axis
g.drawLine(xzero, 50, xzero, ydim-50);
g.drawLine(xzero, 50, (xzero - 5), 55);
g.drawLine(xzero, 50, (xzero + 5), 55);
//x-axis
g.drawLine(50, yzero, xdim-50, yzero);
g.drawLine((xdim-50), yzero, (xdim-55), (yzero + 5));
g.drawLine((xdim-50), yzero, (xdim-55), (yzero - 5));
//Initialise the labelling taking into account the xtic and ytic values
//x-axis labels
if (xmin <= 0){
xpoint = xmin - (xmin%xtic);
}else{
xpoint = xmin - (xmin%xtic) + xtic;
}
do{
xdraw = (int) (50 + (((xpoint-xmin)/(xmax-xmin))*(xdim-100)));
g.drawString(xpoint + "", xdraw, (yzero+10));
xpoint = xpoint + xtic;
}while (xpoint <= xmax);
if (ymin <= 0){
ypoint = ymin - (ymin%ytic);
}else{
ypoint = ymin - (ymin%ytic) + ytic;
}
do{
ydraw = (int) ((ydim - 50) - (((ypoint - ymin)/(ymax-ymin))*(ydim-100)));
g.drawString(ypoint + "", (xzero - 20), ydraw);
ypoint = ypoint + ytic;
}while (ypoint <= ymax);
//Titles and labels
Font f2 = new Font("TimesRoman", Font.BOLD, 14);
g.setFont(f2);
g.drawString(xlabel, (xdim - 100), (yzero + 25));
g.drawString(ylabel, (xzero - 25), 40);
g.drawString(title, (xdim/2 - 75), 20);
//Finding Maximum and Minimun values for the curve
// Draw Lines
g.drawString("Maximum point" + "("+ x1max + "," + ymax + ")", (xdim/2 + 250), 170);
g.drawString("Minimum point" + "("+ x1min + "," + ymin + ")", (xdim/2 + 250), 200);
g.drawString(nameOfPlot1 + " to " + nameOfPlot2, 100, 50);
for (int j = 0; j < size-1; j++)
{
g.drawLine(xx[j], yy[j], xx[j+1], yy[j+1]);
}
}
}
/*------Other classes needed-----------------*/
abstract class Event extends AbstractEvent {
double time;
public boolean lessThan(Comparable y) {
Event e = (Event) y; // Will throw an exception if y is not an Event
return this.time < e.time;
}
}
class Simulator extends AbstractSimulator {
double time ;
public ThreadClass[] theClass = new ThreadClass[20000] ;
int u=0;
double now()
{
time = time + 0.5 ;
return time;
}
void doAllEvents()
{
Event e;
while ( (e= (Event) events.removeFirst()) != null )
{
u++ ;
time = e.time;
//e.execute(this);
//new ThreadClass(e, this, time).start();
theClass[u] = new ThreadClass(e, this, time) ;
}
for(int n=1 ; n<=u ; n++)
{
theClass[n].start();
}
}
}
class ThreadClass extends Thread
{
Event e ;
Simulator sim;
double time ;
public ThreadClass(Event x , Simulator sim1, double time1)
{
e=x;
sim=sim1;
time = time1 ;
}
public void run()
{
time = e.time ;
e.execute(sim) ;
}
}
/*----------------------------------------------*/
class ListQueue extends OrderedSet {
java.util.Vector elements = new java.util.Vector();
void insert(Comparable x) {
int i = 0;
while (i < elements.size() && ((Comparable) elements.elementAt(i)).lessThan(x)) {
i++;
}
elements.insertElementAt(x,i);
}
Comparable removeFirst() {
if (elements.size() ==0) return null;
Comparable x = (Comparable) elements.firstElement();
elements.removeElementAt(0);
return x;
}
Comparable getElement(int i)
{
if (elements.size() ==0) return null;
Comparable x = (Comparable) elements.elementAt(i);
return x ;
}
Object remove(Object x) {
for (int i = 0; i < elements.size(); i++) {
if (elements.elementAt(i).equals(x)) {
Object y = elements.elementAt(i);
elements.removeElementAt(i);
return y;
}
}
return null;
}
public int size() {
return elements.size();
}
}
/*---------------------------------------------------------*/
interface Comparable {
boolean lessThan(Comparable y);
}
abstract class AbstractEvent implements Comparable {
abstract void execute(AbstractSimulator simulator);
}
abstract class OrderedSet {
abstract void insert(Comparable x);
abstract Comparable removeFirst();
abstract Comparable getElement(int i);
abstract int size();
}
class AbstractSimulator {
OrderedSet events;
void insert(AbstractEvent e) {
events.insert(e);
}
AbstractEvent cancel(AbstractEvent e) {
throw new java.lang.RuntimeException("Method not implemented");
}
}
/*--------------------------------------------*/
class Random {
static double exponential(double mean) {
return - mean * Math.log(Math.random());
}
static boolean bernoulli(double p) {
return Math.random() < p;
}
/* .. and other distributions */
}
import javax.swing.*;
import AbstractNetworkButton.*;
import java.util.*;
public class MS extends Event
{
private JButton button ;
String signalNumberServe ;
public int linksForThisInstance ;
public String value ;
public String msName ;
public String msNumber ;
public String linkNameHMS;
public Link[] linkSender = new Link[20] ;
public Link[] linkProcessor = new Link[20] ;
private Vector possibleLinks = new Vector();
private Vector possibleMSLinks = new Vector();
private String name = "MoSt";
private Vector msSignals = new Vector();
private Vector signalsJustInputted = new Vector();
private Vector linkSignalCameFrom = new Vector();
public int i;
/* All The possible signals a MS can send to a BTS */
/*this variable holds how much people are going from one MS to another*/
String movers = "00000";
int sizeOfOneHandOffMessage = 125 ; //bytes
String handoff ;
String findMS ;
String callSetup ;
String callEnd ;
String ack ;
/*Variables that the user can alter from the GUI*/
public int initialAmountOfUsers ;
public MS()
{
}
public MS(String s,int i,ImageIcon icon1, ClickHandler clix)
{
this.i = i ;
button = new JButton(s+i,icon1);
button.setBounds(5,5,90,80);
button.addMouseMotionListener(clix);
button.addMouseListener(clix);
/* Customize a signal for a particular instance */
handoff = "HANDOFFS00200MoSt"+i ;
/*The integer moves is used in findMS tp repersent the amount of people
moved multiplied by the size of one HandOff message*/
//findMS = "FINDMOST"+movers+"MoSt"+i ;
callSetup = "CALLSETU00400MoSt"+i ;
callEnd = "CALLENDS00500MoSt"+i ;
/*Add the possible signals to the "msSignals" vector*/
msSignals.addElement( handoff );
msSignals.addElement( findMS );
msSignals.addElement( callSetup );
msSignals.addElement( callEnd );
/*Values altered by the GUI*/
initialAmountOfUsers = 444 ;
}
public JButton msButtonMethod()
{
return button ;
}
public void receiveLink(Link link1 , Link link2)
{
if(Global.link1Flag==true)
{
linkSender[Global.linkNumber] = new Link();
linkSender[Global.linkNumber]= link2 ;
}
if(Global.link2Flag==true)
{
linkProcessor[Global.linkNumber] = new Link();
linkProcessor[Global.linkNumber] = link1 ;
}
if(Global.link1Flag==false)
{
linkSender[Global.linkNumber] = new Link();
linkSender[Global.linkNumber] = link1 ;
Global.link1Flag = true ;
Global.flagHasBeenTripped = true ;
}
if(Global.link2Flag==false)
{
linkProcessor[Global.linkNumber] = new Link();
linkProcessor[Global.linkNumber]= link2 ;
Global.link2Flag = true ;
}
linkSender[Global.linkNumber].firstNameOfThisLink(name+i);
linkProcessor[Global.linkNumber].lastNameOfThisLink(name+i);
value = Integer.toString(Global.linkNumber);
possibleLinks.add(value);
}
public boolean isConnectionAllowed(JButton b)
{
return true;
}
/*Just before we enter the Simulation We initialize the initial amount of users*/
/*Simulation Part*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
void execute( AbstractSimulator simulator )
{
int sizeOfVector = possibleLinks.size();
while( ((Simulator)simulator).now() <= 610.0 )
{
System.out.println("The MS time is " + ((Simulator)simulator).now());
/*The code here will be divided up into Sender and Processor.
Sender will be underneath while Processor will be on top*/
/*Sender code for MobileStationSignals signals*/
/*---------------------------------------------------------------------*/
/*Selecting a random link*/
/*In this section the total amount of users moving from one MS to
Another will be sorted. And the signals cause by this movement will
also be dealt with*/
/*Select a random amount of people of the initial prople to move*/
for(int linkms =0 ; linkms <possibleLinks.size() ;linkms++)
{
String linkLoop = (String)possibleLinks.elementAt(linkms);
int linkLink = Integer.valueOf(linkLoop).intValue();
linkNameHMS = linkSender[linkLink].getLastNameOfLink() ;
StringBuffer buffer = new StringBuffer(4) ;
for(int m=0 ; m<=3 ;m++)
{
buffer.append(linkNameHMS.charAt(m));
}
msName = buffer.toString();
msNumber = Integer.toString(linkLink);
if(msName.equals("MoSt"))
{
possibleMSLinks.add(msNumber);
}
}
int movingUsers = (int)(Math.random() * (initialAmountOfUsers/5));
int amountOfUsersAtThisInstance = (initialAmountOfUsers - movingUsers) ;
/*Make sure and covnvert the movingUsers value to a Five diget String*/
String movingUsersString = convertTo5Character(movingUsers);
/*Now find all the MS conencted to this MS and choose one and send the
"movingUsers" value to it*/
int randomVectorIndex =(int)(Math.random() * (possibleMSLinks.size()));
String stringValue = (String)possibleMSLinks.elementAt(randomVectorIndex);
int randomLink = Integer.valueOf(stringValue).intValue();
String lastNameOfThisLink = linkSender[randomLink].getLastNameOfLink();
String lastNameOfLinkExcludingNumber = case4(randomLink ,lastNameOfThisLink ) ;
/*Send signal to the choosen MS*/
String signalIndicatingMovement = handoff+movingUsersString;
linkSender[randomLink].addSignalToVector(signalIndicatingMovement);
for(int amount = 0 ; amount < movingUsers ; amount++)
{
/*After sending the signal to a MS it must now alert the BTS*/
int preMovers = sizeOfOneHandOffMessage ;
String justSomeString = convertTo5Character(preMovers);
movers = justSomeString;
findMS = "FINDMOST"+movers+"MoSt"+i ;
String findMobileStation = findMS+lastNameOfThisLink ;
case1(findMobileStation, "BTSt");
}
/*Processor Code*/
/*---------------------------------------------------------------------*/
/* Create a for loop to collect all the signals just inputted
into the Mobile Sttaion. And also store these signals in
a vector */
for(int z =0 ; z < sizeOfVector ; z++)
{
String inputStringValue = (String)possibleLinks.elementAt(z);
int linkProcessorNumber = Integer.valueOf(inputStringValue).intValue();
if(linkProcessor[linkProcessorNumber].size() > 0)
{
String signalNumber = linkProcessor[linkProcessorNumber].removeFirstSignal();
signalNumberServe = signalNumber;
/* Input the collected signal in the "signalsJustInputted" vector */
signalsJustInputted.add(signalNumberServe);
/*Store link it came from in a vector for future reference*/
String presentLink = Integer.toString(linkProcessorNumber);
linkSignalCameFrom.add(presentLink);
}
/*If Link is empty*/
if(linkProcessor[linkProcessorNumber].size() == 0)
{
String signalNumber = "NOTHINGS02000NULL000000";
signalNumberServe = signalNumber ;
signalsJustInputted.add(signalNumberServe);
/*Store link it came from in a vector for future reference*/
String presentLink = Integer.toString(linkProcessorNumber);
linkSignalCameFrom.add(presentLink);
}
}
/*---------------------------------------------------------------------*/
/*Sender code for collected signals*/
/*---------------------------------------------------------------------*/
int sizeOfInputVector = signalsJustInputted.size();
for(int y =0 ; y < sizeOfInputVector ; y++)
{
if(signalsJustInputted.size()==0)
{
}
if(signalsJustInputted.size() > 0)
{
String signalBeingProcessed = (String)signalsJustInputted.elementAt(0);
String str = (String)linkSignalCameFrom.elementAt(0);
int linkThisSignalCameFrom = Integer.valueOf(str).intValue();
/* Extract the relevant info from the signal */
/*------------------------------------------------------*/
/*Here the name of the signal is extracted*/
StringBuffer dest1 = new StringBuffer(8);
for(int i=0 ; i<=7 ; i++)
est1.append(signalBeingProcessed.charAt(i));
String signalName = dest1.toString();
/*Here the component it came from is extracted */
StringBuffer dest2 = new StringBuffer(4);
for(int i=13 ; i<=16 ; i++)
est2.append(signalBeingProcessed.charAt(i));
String networkCompName = dest2.toString();
/*Here the Last Five digits of the Signal is extracted*/
StringBuffer dest3 = new StringBuffer(5);
for(int i=18 ; i<=22 ; i++)
est3.append(signalBeingProcessed.charAt(i));
String lastFiveDigits = dest3.toString();
/*Here the actual components including the number is seperated*/
StringBuffer dest4 = new StringBuffer(5);
for(int i=13 ; i<=17 ; i++)
est4.append(signalBeingProcessed.charAt(i));
String networkCompNameAndNumber = dest4.toString();
/*--------------------------------------------------------------------------------*/
/* Here the signals are processed and then sent out based on the extratced info */
/*--------------------------------------------------------------------------------*/
if((signalName.equals("HANDOFFS")) && (networkCompName.equals("MoSt")))
{
int amountOfNewUsers = Integer.valueOf(lastFiveDigits).intValue();
System.out.println("NEW USERS " + amountOfNewUsers );
initialAmountOfUsers = amountOfUsersAtThisInstance + amountOfNewUsers ;
System.out.println("Total users in " +name + i+ " is now " + initialAmountOfUsers) ;
}
else
{
}
signalsJustInputted.removeElementAt(0);
linkSignalCameFrom.removeElementAt(0);
}
}
simulator.insert( this );
}
}
/*-------------------------------------------------------------------------------*/
/*CONVERSION GO HERE*/
/*-------------------------------------------------------------------------------*/
public String convertTo5Character(int value)
{
String before = Integer.toString(value);
String after ="00000";
if(before.length()==1)
{ after = "0000"+before ;}
if(before.length()==2)
{ after = "000"+before ;}
if(before.length()==3)
{ after = "00"+before ;}
if(before.length()==4)
{ after = "0"+before ;}
if(before.length()==5)
{ after = before ;}
return after ;
}
/*-------------------------------------------------------------------------------*/
/*CASES GO HERE*/
/*-------------------------------------------------------------------------------*/
/*Case One is for finding a link exculuding its number. This method will send a
message to a certain link */
public void case1(String signalName, String component)
{
int linkToAlert =0 ;
for(int fort =0 ; fort<possibleLinks.size() ;fort++)
{
String fortLoop = (String)possibleLinks.elementAt(fort);
int fortLink = Integer.valueOf(fortLoop).intValue();
String lastName = linkSender[fortLink].getLastNameOfLink();
StringBuffer holdLastNameOfThisLink = new StringBuffer(4) ;
for(int y=0 ; y<=3 ;y++)
{
holdLastNameOfThisLink.append(lastName.charAt(y));
}
String lastNameOfLinkExcludingNumber = holdLastNameOfThisLink.toString();
if(lastNameOfLinkExcludingNumber.equals(component))
{
linkToAlert = fortLink ;
linkSender[linkToAlert].addSignalToVector(signalName);
}
}
}
public void case2()
{
}
public void case3()
{
}
/*This is for the MS class only. It chooses a link at random and determines if
the name of the link excuding the number.*/
public String case4(int randomLink , String lastNameOfThisLink)
{
/*If the randomly selcected link is a MS then do the following....*/
StringBuffer holdLastNameOfThisLink = new StringBuffer(4);
for(int y=0 ; y<=3 ;y++)
{ holdLastNameOfThisLink.append(lastNameOfThisLink.charAt(y));}
String lastNameOfLinkExcludingNumber = holdLastNameOfThisLink.toString();
return lastNameOfLinkExcludingNumber ;
}
}
import javax.swing.*;
import AbstractNetworkButton.*;
import java.util.*;
public class BTS extends Event
{
private JButton button ;
String signalNumberServe ;
public String value ;
private Vector possibleLinks = new Vector();
public int linksForThisInstance = 0 ;
public Link[] linkSender = new Link[20] ;
public Link[] linkProcessor = new Link[20] ;
private Vector msSignals = new Vector();
private Vector signalsJustInputted = new Vector();
private Vector linkSignalCameFrom = new Vector();
private String name = "BTSt";
public int i ;
public double time1 ;
/*All the signals the BTS can send*/
String listOfBTSinArea ;
String ackOfHandOverDuties ;
String accept ;
String noChannelAvailable ;
String end ;
public BTS()
{
}
public BTS(String s,int i,ImageIcon icon1, ClickHandler clix) {
this.i =i ;
button = new JButton(s+i,icon1);
button.setBounds(5,5,90,80);
button.addMouseMotionListener(clix);
button.addMouseListener(clix);
/* Customize a signal for a particular instance */
listOfBTSinArea = "LSTOFBTS00100BTSt"+i+"00000" ;
ackOfHandOverDuties = "ACKHODUT00900BTSt"+i+"00000" ;
accept = "ACCEPTMS00200BTSt"+i;
noChannelAvailable = "NOCHAAVL00223BTSt"+i+"00450" ;
end = "ENDCALLS00435BTSt"+i+"00100" ;
msSignals.addElement( ackOfHandOverDuties );
msSignals.addElement( noChannelAvailable );
msSignals.addElement( end );
msSignals.addElement( accept );
}
public JButton btsButtonMethod()
{
return button ;
}
public void receiveLink(Link link1 , Link link2)
{
if(Global.link1Flag==true)
{
linkSender[Global.linkNumber] = new Link();
linkSender[Global.linkNumber]= link2 ;
}
if(Global.link2Flag==true)
{
linkProcessor[Global.linkNumber] = new Link();
linkProcessor[Global.linkNumber] = link1 ;
}
if(Global.link1Flag==false)
{
linkSender[Global.linkNumber] = new Link();
linkSender[Global.linkNumber] = link1 ;
Global.link1Flag = true ;
Global.flagHasBeenTripped = true ;
}
if(Global.link2Flag==false)
{
linkProcessor[Global.linkNumber] = new Link();
linkProcessor[Global.linkNumber]= link2 ;
Global.link2Flag = true ;
}
linkSender[Global.linkNumber].firstNameOfThisLink( name + i );
linkProcessor[Global.linkNumber].lastNameOfThisLink( name +i);
value = Integer.toString(Global.linkNumber);
possibleLinks.add(value);
}
public boolean isConnectionAllowed(JButton b)
{
return true;
}
/*Simulation Part*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
void execute( AbstractSimulator simulator )
{
int sizeOfVector = possibleLinks.size();
while (((Simulator)simulator).now() <= 610.0)
{
System.out.println("The time is " + ((Simulator)simulator).now());
/*The code here will be divided up into Sender and Processor.
Processor will be underneath while sender will be on top*/
/*Sender code for MobileStationSignals signals*/
/*---------------------------------------------------------------------*/
/*Processor Code*/
/*---------------------------------------------------------------------*/
/* Create a for loop to collect all the signals just inputted
into the Mobile Sttaion. And also store these signals in
a vector */
for(int z =0 ; z < sizeOfVector ; z++)
{
String inputStringValue = (String)possibleLinks.elementAt(z);
int linkProcessorNumber = Integer.valueOf(inputStringValue).intValue();
if(linkProcessor[linkProcessorNumber].size() > 0)
{
String signalNumber = linkProcessor[linkProcessorNumber].removeFirstSignal();
signalNumberServe = signalNumber;
/* Input the collected signal in the "signalsJustInputted" vector */
signalsJustInputted.add(signalNumberServe);
/*Store link it came from in a vector for future reference*/
String presentLink = Integer.toString(linkProcessorNumber);
linkSignalCameFrom.add(presentLink);
}
/*If Link is empty*/
if(linkProcessor[linkProcessorNumber].size()==0)
{
String signalNumber = "NOTHINGS02000NULL000000";
signalNumberServe = signalNumber ;
signalsJustInputted.add(signalNumberServe);
/*Store link it came from in a vector for future reference*/
String presentLink = Integer.toString(linkProcessorNumber);
linkSignalCameFrom.add(presentLink);
}
}
/*---------------------------------------------------------------------*/
/*Sender code for collected signals*/
/*---------------------------------------------------------------------*/
int sizeOfInputVector = signalsJustInputted.size();
for(int y =0 ; y < sizeOfInputVector ; y++)
{
if(signalsJustInputted.size()==0)
{
System.out.println("No signals yet");
//break;
}
if(signalsJustInputted.size() > 0)
{
String signalBeingProcessed = (String)signalsJustInputted.elementAt(0);
String str = (String)linkSignalCameFrom.elementAt(0);
int linkThisSignalCameFrom = Integer.valueOf(str).intValue();
/* Extract the relevant info from the signal */
/*----------------------------------------------------------------*/
/*Here the name of the signal is extracted*/
StringBuffer dest1 = new StringBuffer(8);
for(int i=0 ; i<=7 ; i++)
est1.append(signalBeingProcessed.charAt(i));
String signalName = dest1.toString();
/*Here the component it came from is extracted */
StringBuffer dest2 = new StringBuffer(4);
for(int i=13 ; i<=16 ; i++)
est2.append(signalBeingProcessed.charAt(i));
String networkCompName = dest2.toString();
/*Here the Last Five digits of the Signal is extracted*/
StringBuffer dest3 = new StringBuffer(5);
for(int i=18 ; i<=22 ; i++)
est3.append(signalBeingProcessed.charAt(i));
String lastFiveDigits = dest3.toString();
/*Here the actual components including the number is seperated*/
StringBuffer dest4 = new StringBuffer(5);
for(int i=13 ; i<=17 ; i++)
est4.append(signalBeingProcessed.charAt(i));
String networkCompNameAndNumber = dest4.toString();
/*--------------------------------------------------------------------------------*/
/* Here the signals are processed and then sent out based on the extratced info */
/*--------------------------------------------------------------------------------*/
if((signalName.equals("FINDMOST")) && (networkCompName.equals("MoSt")))
{
case1(signalBeingProcessed ,"BSCS");
case1(signalBeingProcessed ,"MoSt");
}
/*-------------------------------PROBEMESSAGE HANDLER-------------------------------*/
/*This looks for the handedover MS's. Its just checks to see if the MS exist
at the end of the BTS.*/
if((signalName.equals("PROBEMES")) && (networkCompName.equals("BSCS")))
{
String acceptReturn= accept+lastFiveDigits ;
case2(acceptReturn,lastFiveDigits,linkThisSignalCameFrom);
}
/*-------------TAKING CARE OF ASSIGNCM message sent from the BSC------------------*/
/*After receiving orders from the BSC to take control of a few MS that just moved into
it cell it must send back and ackowlegement message as well as notify all the MS that it
is control of them now and must update them and take care of them */
if((signalName.equals("ASSIGNCM")) && (networkCompName.equals("BSCS")))
{
case3(ackOfHandOverDuties,linkThisSignalCameFrom);
}
/*-------------------------------------------------------------------------------*/
/*If there is no signal to process then BTS uses this free time to
alert all the MS of the potential BTS's available for hanfoff*/
if((signalName.equals("NOTHINGS")))
{
case1(listOfBTSinArea ,"MoSt");
}
signalsJustInputted.removeElementAt(0);
linkSignalCameFrom.removeElementAt(0);
}
}
simulator.insert( this );
}
}
/*-------------------------------------------------------------------------------*/
/*CONVERSION GO HERE*/
/*-------------------------------------------------------------------------------*/
public String convertTo5Character(int value)
{
String before = Integer.toString(value);
String after ="00000";
if(before.length()==1)
{ after = "0000"+before ;}
if(before.length()==2)
{ after = "000"+before ;}
if(before.length()==3)
{ after = "00"+before ;}
if(before.length()==4)
{ after = "0"+before ;}
if(before.length()==5)
{ after = before ;}
return after ;
}
/*-------------------------------------------------------------------------------*/
/*CASES GO HERE*/
/*-------------------------------------------------------------------------------*/
/*------------------------------------------CASE1-----------------------------------*/
/*Case One is for finding a link exculuding its number. This method will send a
message to a certain link type */
public void case1(String signalName, String component)
{
int linkToAlert =0 ;
for(int fort =0 ; fort<possibleLinks.size() ;fort++)
{
String fortLoop = (String)possibleLinks.elementAt(fort);
int fortLink = Integer.valueOf(fortLoop).intValue();
String lastName = linkSender[fortLink].getLastNameOfLink();
StringBuffer holdLastNameOfThisLink = new StringBuffer(4) ;
for(int y=0 ; y<=3 ;y++)
{
holdLastNameOfThisLink.append(lastName.charAt(y));
}
String lastNameOfLinkExcludingNumber = holdLastNameOfThisLink.toString();
if(lastNameOfLinkExcludingNumber.equals(component))
{
linkToAlert = fortLink ;
linkSender[linkToAlert].addSignalToVector(signalName);
}
}
}
/*------------------------------------------CASE2-----------------------------------*/
public void case2(String signalName , String lastFiveDigits , int originalLink)
{
for(int fort =0 ; fort <possibleLinks.size() ;fort++)
{
String fortLoop = (String)possibleLinks.elementAt(fort);
int fortLink = Integer.valueOf(fortLoop).intValue();
String nameOfLink = linkSender[fortLink].getLastNameOfLink();
if(nameOfLink.equals(lastFiveDigits))
{
/*Send a messsage to the original link*/
linkSender[originalLink].addSignalToVector(signalName);
}
}
}
/*This sends one of its own messages to a link a message came on*/
public void case3(String signalName , int originalLink)
{
linkSender[originalLink].addSignalToVector(signalName);
}
}
import javax.swing.*;
import AbstractNetworkButton.*;
import java.util.*;
public class BSC extends Event
{
private JButton button ;
String signalNumberServe ;
public int linksForThisInstance ;
public String value ;
public Link[] linkSender = new Link[20] ;
public Link[] linkProcessor = new Link[20] ;
private Vector possibleLinks = new Vector();
private String name = "BSCS";
private String nameOfBtsWhichToRelieveDuties ;
private Vector msSignals = new Vector();
private Vector signalsJustInputted = new Vector();
private Vector linkSignalCameFrom = new Vector();
public int i;
/* All The possible signals a MS can send to a BTS */
String probeMessage ;
String assignCommand ;
String relieveBTSofDuties ;
public BSC()
{
}
public BSC(String s,int i,ImageIcon icon1, ClickHandler clix)
{
this.i = i ;
button = new JButton(s+i,icon1);
button.setBounds(5,5,90,80);
button.addMouseMotionListener(clix);
button.addMouseListener(clix);
/* Customize a signal for a particular instance */
probeMessage = "PROBEMES00500BSCS"+i ;
assignCommand = "ASSIGNCM03000BSCS"+i+00000 ;
relieveBTSofDuties = "RELIEBTS00235BSCS"+i+00000 ;
/*Add the possible signals to the "msSignals" vector*/
msSignals.addElement( probeMessage );
msSignals.addElement( assignCommand );
}
public JButton bscButtonMethod()
{
return button ;
}
public void receiveLink(Link link1 , Link link2)
{
if(Global.link1Flag==true)
{
linkSender[Global.linkNumber] = new Link();
linkSender[Global.linkNumber]= link2 ;
}
if(Global.link2Flag==true)
{
linkProcessor[Global.linkNumber] = new Link();
linkProcessor[Global.linkNumber] = link1 ;
}
if(Global.link1Flag==false)
{
linkSender[Global.linkNumber] = new Link();
linkSender[Global.linkNumber] = link1 ;
Global.link1Flag = true ;
Global.flagHasBeenTripped = true ;
}
if(Global.link2Flag==false)
{
linkProcessor[Global.linkNumber] = new Link();
linkProcessor[Global.linkNumber]= link2 ;
Global.link2Flag = true ;
}
linkSender[Global.linkNumber].firstNameOfThisLink( name + i );
linkProcessor[Global.linkNumber].lastNameOfThisLink( name +i);
value = Integer.toString(Global.linkNumber);
possibleLinks.add(value);
}
public boolean isConnectionAllowed(JButton b)
{
return true;
}
/*Simulation Part*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
void execute( AbstractSimulator simulator )
{
int sizeOfVector = possibleLinks.size();
//time += Random.exponential( 1.0 );
while( ((Simulator)simulator).now() <= 610.0 )
{
/*The code here will be divided up into Sender and Processor.
Processor will be underneath while sender will be on top*/
/*Sender code for MobileStationSignals signals*/
/*---------------------------------------------------------------------*/
/*Processor Code*/
/*---------------------------------------------------------------------*/
/* Create a for loop to collect all the signals just inputted
into the Mobile Sttaion. And also store these signals in
a vector */
for(int z =0 ; z < sizeOfVector ; z++)
{
String inputStringValue = (String)possibleLinks.elementAt(z);
int linkProcessorNumber = Integer.valueOf(inputStringValue).intValue();
if(linkProcessor[linkProcessorNumber].size() > 0)
{
String signalNumber = linkProcessor[linkProcessorNumber].removeFirstSignal();
signalNumberServe = signalNumber;
/* Input the collected signal in the "signalsJustInputted" vector */
signalsJustInputted.add(signalNumberServe);
/*Store link it came from in a vector for future reference*/
String presentLink = Integer.toString(linkProcessorNumber);
linkSignalCameFrom.add(presentLink);
}
/*If Link is empty*/
if(linkProcessor[linkProcessorNumber].size() == 0)
{
String signalNumber = "NOTHINGS00000NULL000000";
signalNumberServe = signalNumber ;
signalsJustInputted.add(signalNumberServe);
/*Store link it came from in a vector for future reference*/
String presentLink = Integer.toString(0);
linkSignalCameFrom.add(presentLink);
}
}
/*---------------------------------------------------------------------*/
/*Sender code for collected signals*/
/*---------------------------------------------------------------------*/
int sizeOfInputVector = signalsJustInputted.size();
for(int y =0 ; y < sizeOfInputVector ; y++)
{
if(signalsJustInputted.size()==0)
{
System.out.println("No signals yet");
}
if(signalsJustInputted.size() > 0)
{
String signalBeingProcessed = (String)signalsJustInputted.elementAt(0);
String str = (String)linkSignalCameFrom.elementAt(0);
int linkThisSignalCameFrom = Integer.valueOf(str).intValue();
/* Extract the relevant info from the signal */
/*------------------------------------------------------*/
/*Here the name of the signal is extracted*/
StringBuffer dest1 = new StringBuffer(8);
for(int i=0 ; i<=7 ; i++)
est1.append(signalBeingProcessed.charAt(i));
String signalName = dest1.toString();
/*Here the component it came from is extracted */
StringBuffer dest2 = new StringBuffer(4);
for(int i=13 ; i<=16 ; i++)
est2.append(signalBeingProcessed.charAt(i));
String networkCompName = dest2.toString();
/*Here the Last Five digits of the Signal is extracted*/
StringBuffer dest3 = new StringBuffer(5);
for(int i=18 ; i<=22 ; i++)
est3.append(signalBeingProcessed.charAt(i));
String lastFiveDigits = dest3.toString();
/*Here the actual components including the number is seperated*/
StringBuffer dest4 = new StringBuffer(5);
for(int i=13 ; i<=17 ; i++)
est4.append(signalBeingProcessed.charAt(i));
String networkCompNameAndNumber = dest4.toString();
/*--------------------------------------------------------------------------------*/
/* Here the signals are processed and then sent out based on the extratced info */
/*--------------------------------------------------------------------------------*/
if((signalName.equals("FINDMOST")) && (networkCompName.equals("MoSt")))
{
String probeMessageAlt = probeMessage+lastFiveDigits ;
case1(probeMessageAlt,"BTSt") ;
nameOfBtsWhichToRelieveDuties = networkCompNameAndNumber ;
}
/*-----------AFTER IT FINDS THE REQUIRED MS THAT THE MS ARE HANDEDOVER TOO
----------------------IT SENDS A COMMAND TAKE OEVER MESSAGE--------------*/
if((signalName.equals("ACCEPTMS")) && (networkCompName.equals("BTSt")))
{
case3(assignCommand,linkThisSignalCameFrom);
}
/*If it recives a ackOfHandOverDuties signal from the BTS it must relieve the former
---------------------------------BTS of its duties---------------------------------*/
if((signalName.equals("ACKHODUT")) && (networkCompName.equals("BTSt")))
{
case4(relieveBTSofDuties,nameOfBtsWhichToRelieveDuties);
}
/*----------------------------------------------------------------------------------*/
/* if((signalName.equals("NOTHINGS")))
{
//alert MSC of handovers
//case1(probeMessage,"BTSt") ;
} */
signalsJustInputted.removeElementAt(0);
linkSignalCameFrom.removeElementAt(0);
}
}
simulator.insert( this );
}
}
/*-------------------------------------------------------------------------------*/
/*CONVERSION GO HERE*/
/*-------------------------------------------------------------------------------*/
public String convertTo5Character(int value)
{
String before = Integer.toString(value);
String after ="00000";
if(before.length()==1)
{ after = "0000"+before ;}
if(before.length()==2)
{ after = "000"+before ;}
if(before.length()==3)
{ after = "00"+before ;}
if(before.length()==4)
{ after = "0"+before ;}
if(before.length()==5)
{ after = before ;}
return after ;
}
/*-------------------------------------------------------------------------------*/
/*CASES GO HERE*/
/*-------------------------------------------------------------------------------*/
/*------------------------------------------CASE1-----------------------------------*/
/*Case One is for finding a link exculuding its number. This method will send a
message to a certain type */
public void case1(String signalName, String component)
{
int linkToAlert =0 ;
for(int fort =0 ; fort<possibleLinks.size() ;fort++)
{
String fortLoop = (String)possibleLinks.elementAt(fort);
int fortLink = Integer.valueOf(fortLoop).intValue();
String lastName = linkSender[fortLink].getLastNameOfLink();
StringBuffer holdLastNameOfThisLink = new StringBuffer(4) ;
for(int y=0 ; y<=3 ;y++)
{
holdLastNameOfThisLink.append(lastName.charAt(y));
}
String lastNameOfLinkExcludingNumber = holdLastNameOfThisLink.toString();
if(lastNameOfLinkExcludingNumber.equals(component))
{
linkToAlert = fortLink ;
linkSender[linkToAlert].addSignalToVector(signalName);
}
}
}
/*-------------------------------------CASE2-----------------------------------*/
public void case2(String signalName , String lastFiveDigits , int originalLink)
{
for(int fort =0 ; fort <possibleLinks.size() ;fort++)
{
String fortLoop = (String)possibleLinks.elementAt(fort);
int fortLink = Integer.valueOf(fortLoop).intValue();
String nameOfLink = linkSender[fortLink].getLastNameOfLink();
if(nameOfLink.equals(lastFiveDigits))
{
/*Send a messsage to the original link*/
linkSender[originalLink].addSignalToVector(signalName);
}
}
}
/*---------------------------------CASE3-----------------------------------------*/
/*This sends one of its own messages to a link a message came on*/
public void case3(String signalName , int originalLink)
{
linkSender[originalLink].addSignalToVector(signalName);
}
/*----------------------------------CASE4----------------------------------------*/
/*This sends one of its own messages to a sepcified link*/
public void case4(String signalName , String specificComponentToLookFor)
{
for(int fort =0 ; fort <possibleLinks.size() ;fort++)
{
String fortLoop = (String)possibleLinks.elementAt(fort);
int fortLink = Integer.valueOf(fortLoop).intValue();
String nameOfLink = linkSender[fortLink].getLastNameOfLink();
if(nameOfLink.equals(specificComponentToLookFor))
{
linkSender[fortLink].addSignalToVector(signalName);
}
}
}
}