Skip to content

Commit

Permalink
rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickduhaime committed Apr 29, 2018
1 parent ffb9abf commit fdf83c0
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 91 deletions.
Binary file modified .vs/INF1009/v15/.suo
Binary file not shown.
Binary file modified .vs/INF1009/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/INF1009/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
Binary file modified .vs/INF1009/v15/sqlite3/storage.ide
Binary file not shown.
Binary file modified .vs/INF1009/v15/sqlite3/storage.ide-wal
Binary file not shown.
15 changes: 12 additions & 3 deletions INF1009/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class Form1 : Form
private Thread networkWriteThread, transportWriteThread, transportReadThread, networkReadThread, processingThread;
private const string S_lec = "s_lec.txt";
private string d_msg;
private string d_msgType;
delegate void UIDisplayText(string text);

public Form1()
Expand Down Expand Up @@ -63,7 +64,7 @@ private void openThreads()

private void buttonStart_Click(object sender, EventArgs e)
{

richTextBoxGen.Clear();
try
{
reset();
Expand Down Expand Up @@ -96,6 +97,7 @@ public void reset()

private void buttonReset_Click(object sender, EventArgs e)
{
nbTest = 1;
transport.Stop();
rtbL_ecr.Clear();
rtbL_lec.Clear();
Expand Down Expand Up @@ -132,6 +134,7 @@ private void buttonGenerate_Click(object sender, EventArgs e)
string dest = transport.setDestAddress();
int intDest = Int32.Parse(dest);
string source = transport.setSourceAddress(intDest);
d_msgType = "GenTest";

d_msg = "N_CONNECT " + dest + " " + source + "\n" +
"N_DATA test no.: " + nbTest + "\n" +
Expand All @@ -143,16 +146,22 @@ private void buttonGenerate_Click(object sender, EventArgs e)

private void buttonSend2File_Click(object sender, EventArgs e)
{
if (d_msgType == "GenTest")
richTextBoxGen.AppendText("\n Test sent to file !");
else if (d_msgType == "TestFile")
richTextBoxGen.AppendText("\n Test file sent !");
transport.Stop();
File.AppendAllText(S_lec, d_msg + Environment.NewLine);

richTextBoxGen.Clear();
nbTest++;
transport.Restart();
}

private void buttonTest_Click(object sender, EventArgs e)
{
richTextBoxGen.Clear();
richTextBoxGen.AppendText("\n Test file loaded !");
d_msgType = "TestFile";

d_msg = "N_CONNECT 1 11\n" +
"N_DATA Start testing INF1009\n" +
"N_DISCONNECT 1 11\n" +
Expand Down
53 changes: 44 additions & 9 deletions INF1009/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Network
private FileStream file2Transport;
private StreamWriter writeFromTransport;
private StreamWriter write2Transport;
private int respAddr, sentCount;
private int sentCount;
byte[] sourceAddr;
byte[] destAddr;
byte[] outputNo;
Expand Down Expand Up @@ -59,7 +59,6 @@ public void Start()
outputNo = new byte[1];
newConnection(outputNo);

respAddr = rnd.Next();
pr = 0;
receivedData = "";
disconnected = false;
Expand Down Expand Up @@ -159,22 +158,60 @@ public void transportRead()
else
{
if (transportNpdu.type == "N_CONNECT.req")

{
msg = "N_CONNECT " + transportNpdu.destAddr + " " + transportNpdu.sourceAddr + " route: " + transportNpdu.routeAddr;
int intSource = int.Parse(transportNpdu.sourceAddr);
int intDest = int.Parse(transportNpdu.destAddr);
sourceAddr[0] = (byte)intSource;
destAddr[0] = (byte)intDest;

if (intSource > 249 || intDest > 249)
{
transportNpdu.routeAddr = " Error, not found !";
}
else
{
if (intSource >= 0 && intSource <= 99)
{
if (intDest >= 0 && intDest <= 99)
transportNpdu.routeAddr = "" + intDest;
else if (intDest >= 100 && intDest <= 199)
transportNpdu.routeAddr = "" + 255;
else if (intDest >= 200 && intDest <= 249)
transportNpdu.routeAddr = "" + 254;
}
else if (intSource >= 100 && intSource <= 199)
{
if (intDest >= 0 && intDest <= 99)
transportNpdu.routeAddr = "" + 250;
else if (intDest >= 100 && intDest <= 199)
transportNpdu.routeAddr = "" + intDest;
else if (intDest >= 200 && intDest <= 249)
transportNpdu.routeAddr = "" + 253;
}
else if (intSource >= 200 && intSource <= 249)
{
if (intDest >= 0 && intDest <= 99)
transportNpdu.routeAddr = "" + 251;
else if (intDest >= 100 && intDest <= 199)
transportNpdu.routeAddr = "" + 252;
else if (intDest >= 200 && intDest <= 249)
transportNpdu.routeAddr = "" + intDest;
}

}

msg = "N_CONNECT " + transportNpdu.destAddr + " " + transportNpdu.sourceAddr + " route:" + transportNpdu.routeAddr;
writeFromTransport.WriteLine(msg);
Form1._UI.write2L_lec(msg);

sourceAddr[0] = (byte)int.Parse(transportNpdu.sourceAddr);
destAddr[0] = (byte)int.Parse(transportNpdu.destAddr);
if (sourceAddr[0] % 27 == 0 || int.Parse(transportNpdu.sourceAddr) > 249 || int.Parse(transportNpdu.destAddr) > 249)
{
disconnected = true;
connected = false;

npdu2Transport = new Npdu();
npdu2Transport.type = "N_DISCONNECT.ind";
npdu2Transport.routeAddr = respAddr.ToString();
npdu2Transport.target = "00000010";
npdu2Transport.connection = "255";
network2Transport.Enqueue(npdu2Transport);
Expand All @@ -185,7 +222,6 @@ public void transportRead()

npdu2Transport = new Npdu();
npdu2Transport.type = "N_CONNECT.conf";
npdu2Transport.routeAddr = respAddr.ToString();
npdu2Transport.sourceAddr = sourceAddr[0].ToString();
npdu2Transport.destAddr = destAddr[0].ToString();
npdu2Transport.connection = outputNo[0].ToString();
Expand Down Expand Up @@ -250,7 +286,6 @@ public void transportRead()

npdu2Transport = new Npdu();
npdu2Transport.type = "N_DISCONNECT.ind";
npdu2Transport.routeAddr = respAddr.ToString();

packet4Processing = Packet.encapsulateRelease(outputNo[0], sourceAddr[0], destAddr[0], true);
string packetType = "release";
Expand Down
2 changes: 1 addition & 1 deletion INF1009/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static PACKET decapBytes(byte[] received)

currentPacket.dataArray = temp;
}

return currentPacket;
}

Expand Down
49 changes: 1 addition & 48 deletions INF1009/Transport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ public void Stop()
public void Restart()
{
end = false;

inputFile = new FileStream(S_lec, FileMode.OpenOrCreate, FileAccess.Read);
reader = new StreamReader(inputFile);
outputFile = new FileStream(S_ecr, FileMode.OpenOrCreate, FileAccess.Write);
writer = new StreamWriter(outputFile);

resetFiles();
Start();
}
Expand Down Expand Up @@ -154,51 +152,6 @@ public string setSourceAddress(int intDest)
return result;
}

/**
* Methode setRouteAddress definit une addresse de routage selon
* l'enonce de travail. Par contre cette adresse n'est pas utilise
* par le programme, la methode et la variable de routage ne
* servent pas, j'ai donc ecris la route dans une variable du Npdu
*/
private string setRouteAddress(string dest, string source)
{
string result = null;

int intResult = -1;
int intSource = Int32.Parse(source);
int intDest = Int32.Parse(dest);

if (intSource >= 0 && intSource <= 99)
{
if (intDest >= 0 && intDest <= 99)
intResult = intDest;
else if (intDest >= 100 && intDest <= 199)
intResult = 255;
else if (intDest >= 200 && intDest <= 249)
intResult = 254;
}
else if (intSource >= 100 && intSource <= 199)
{
if (intDest >= 0 && intDest <= 99)
intResult = 250;
else if (intDest >= 100 && intDest <= 199)
intResult = intDest;
else if (intDest >= 200 && intDest <= 249)
intResult = 253;
}
else if (intSource >= 200 && intSource <= 249)
{
if (intDest >= 0 && intDest <= 99)
intResult = 251;
else if (intDest >= 100 && intDest <= 199)
intResult = 252;
else if (intDest >= 200 && intDest <= 249)
intResult = intDest;
}

result = result + intResult;
return result;
}

/**
* Methode networkWrite (ecrire_vers_reseau) qui lit le fichier s_lec.txt
Expand Down Expand Up @@ -232,7 +185,7 @@ public void networkWrite()
networkNNpdu.type = "N_CONNECT.req";
networkNNpdu.destAddr = settings[1];
networkNNpdu.sourceAddr = settings[2];
networkNNpdu.routeAddr = setRouteAddress(settings[1], settings[2]);
networkNNpdu.routeAddr = "";
valid = true;
}
else if (settings[0] == "N_DATA")
Expand Down
Binary file modified INF1009/bin/Debug/INF1009.exe
Binary file not shown.
Binary file modified INF1009/bin/Debug/INF1009.pdb
Binary file not shown.
28 changes: 17 additions & 11 deletions INF1009/bin/Debug/l_ecr.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
N_CONNECT 1 11 route: 1
N_CONNECT 1 11 route:1
N_DATA Start testing INF1009
N_CONNECT 47 15 route: 47
N_CONNECT 47 15 route:47
N_DATA negative Acknoledgment
N_CONNECT 200 27 route: 254
N_CONNECT 200 500 route: -1
N_CONNECT 9 19 route: 9
N_DISCONNECT 47
N_CONNECT 200 27 route:254
N_CONNECT 200 500 route: Error, not found !
N_CONNECT 9 19 route:9
N_DATA multiple of 19 - no awnser
N_DISCONNECT 9
N_CONNECT 12 13 route: 12
N_CONNECT 58 217 route: 251
N_DATA This is the last test, this program was written for the recognition of the achievements of Patrick Duhaime for the course INF1009 ...
N_DISCONNECT 58
e INF1009 ...
N_CONNECT 12 13 route:12
43 route:84
N_DATA test no.: 8
N_DISCONNECT 84
N_CONNECT 1 11 route:1
N_DATA Start testing INF1009
achievements of Patrick Duhaime for the course INF1009 ...
N_DISCONNECT 58
d quid est quod in hac causa maxime homines admirentur et reprehendant meum consilium, cum ego idem antea multa decreverim, que magis ad hominis dignitatem quam ad rei publicae necessitatem pertinerent? Supplicationem quindecim dierum decrevi sententia mea
N_CONNECT 118 207 route:252
N_DATA test no.: 2
N_DISCONNECT 118
t meum consilium, cum ego idem antea multa decreverim, que magis ad hominis dignitatem quam ad rei publicae necessitatem pertinerent? Supplicationem quindecim dierum decrevi sententia mea
N_DISCONNECT 58
19 changes: 9 additions & 10 deletions INF1009/bin/Debug/l_lec.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
N_CONNECT dest Address :1 source Address: 11
N_DATA transferring network data
N_CONNECT dest Address :47 source Address: 15
N_DISCONNECT Closed by Client
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
N_DISCONNECT Closed by Client
N_CONNECT dest Address :58 source Address: 217
N_DATA transferring network data
N_DATA transferring network data
N_DATA transferring network data
N_DATA transferring network data
data
N_DISCONNECT Closed by Client
N_CONNECT dest Address :248 source Address: 88
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
TA transferring network data
N_DATA transferring network data
N_CONNECT dest Address :183 source Address: 232
N_DATA transferring network data
N_DATA transferring network data
N_DISCONNECT Closed by Client
ATA transferring network data
N_CONNECT dest Address :84 source Address: 43
N_DATA transferring network data
N_DISCONNECT Closed by Client
ta
N_DATA transferring network data
N_DISCONNECT Closed by Client
N_CONNECT dest Address :1 source Address: 11
N_DATA transferring network data
transferring network data
N_DATA transferring network data
N_DATA transferring network data
N_DATA transferring network data
Expand Down
20 changes: 11 additions & 9 deletions INF1009/bin/Debug/s_ecr.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
connection: 5 Connection established
connection: 5 dest Address: 1 source Address: 11
connection: 3 Connection established
connection: 3 dest Address: 47 source Address: 15
connection: 7 Connection established
connection: 7 disconnected Closed by Client
connection: 1 Connection established
connection: 1 dest Address: 1 source Address: 11
connection: 6 Connection established
connection: 6 dest Address: 47 source Address: 15
connection: 6 disconnected Closed by Client
connection: 0 Connection established


connection: 0 disconnected Closed by Client
lient
connection: 1 Connection established
connection: 1 disconnected Closed by Client
connection: 5 Connection established
connection: 5 disconnected Closed by Client
ient
: 0 disconnected Closed by Client
connection: 2 Connection established
connection: 2 dest Address: 58 source Address: 217
connection: 2 disconnected Closed by Client
Expand Down
Binary file modified INF1009/obj/Debug/INF1009.exe
Binary file not shown.
Binary file modified INF1009/obj/Debug/INF1009.pdb
Binary file not shown.

0 comments on commit fdf83c0

Please sign in to comment.