Проектирование и разработка сетевых броузеров на основе теоретико-графовых моделей
push(k);
While k<>target do begin
push(vertexArr[k].mark.PrevPtr);
k:=vertexArr[k].mark.PrevPtr;
End;
End;
Procedure TRouter.Send2NextRouter(batch:TBatch;currentRouter:byte);
Begin
Delay(DelayRouterReceive+AMatr[currentRouter,OptimalPath[OptPathPtr]].link);
showtime(wherex,wherey);
writeln('> router',currentRouter,
' says : I send data ','"',batch.data,'"',' from ',batch.from.router,'.',batch.from.domain,'.',
batch.fromp,' to router',OptimalPath[OptPathPtr]);
routers[OptimalPath[OptPathPtr]].memory:=batch;
inc(OptPathPtr);
routers[currentRouter].memory.data:=''{clear memory}
End;
Procedure TRouter.receive(routerNum:byte;batch:TBatch);
Begin
Delay(DelayRouterReceive);
showtime(wherex,wherey);
writeln('> router',routerNum,
' says : I receive data ','"',batch.data,'"',' from ',batch.from.router,'.',batch.from.domain,'.',
batch.fromp);
End;
Procedure TRouter.send2comp(batch:TBatch);
VAR i:byte;tmpTo,tmpFrom:TAddr;
Begin
Delay(DelayInDomain);
tmpTo:=batch.to_;tmpFrom:=batch.from;
for i:=1 to 38 do if
(computers[i].addr.router=tmpTo.router) AND (computers[i].addr.domain=tmpTo.domain)
AND (computers[i].addrp=tmpTop) then break;
computers[i].mem:=batch; {Send !}
showtime(wherex,wherey);
writeln('> router',tmpTo.router,
' says : I send data ','"',batch.data,'"',' to ',batch.to_.router,'.',batch.to_.domain,'.',
batch.to_p);
routers[tmpTo.router].memory.data:='';{clear memory}
End;
Procedure Initialization;
VAR i,j:integer;
Begin
{------------- INITIALIZATION PART -------------}
FOR i:=1 to 7 do begin {routers initialization}
routers[i].num:=i;routers[i].state:=true;
routers[i].memory.data:='';
for j:=1 to 20 do routers[i].memory.path[j]:=0;
END;
routers[1].x:=120;routers[1].y:=300;
routers[2].x:=250;routers[2].y:=100;
routers[3].x:=320;routers[3].y:=300;
routers[4].x:=300;routers[4].y:=420;
routers[5].x:=500;routers[5].y:=420;
routers[6].x:=540;routers[6].y:=200;
routers[7].x:=550;routers[7].y:=100;
FOR i:=1 to 38 do computers[i].mem.data:='';{computers initialization}
j:=1;
for i:=1 to 4 do begin {router 1, domain 1}
computers[i].addr.router:=1;computers[i].addr.domain:=1;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=5 to 10 do begin {router 1, domain 2}
computers[i].addr.router:=1;computers[i].addr.domain:=2;
computers[i].addrp:=j;inc(j);
end; {router 2, domain 1}
computers[11].addr.router:=2;computers[11].addr.domain:=1;computers[11].addrp:=1;
j:=1;
for i:=12 to 14 do begin {router 2, domain 2}
computers[i].addr.router:=2;computers[i].addr.domain:=2;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=15 to 17 do begin {router 3, domain 1}
computers[i].addr.router:=3;computers[i].addr.domain:=1;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=18 to 20 do begin {router 4, domain 1}
computers[i].addr.router:=4;computers[i].addr.domain:=1;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=21 to 25 do begin {router 4, domain 2}
computers[i].addr.router:=4;computers[i].addr.domain:=2;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=26 to 30 do begin {router 5, domain 1}
computers[i].addr.router:=5;computers[i].addr.domain:=1;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=31 to 34 do begin {router 6, domain 1}
computers[i].addr.router:=6;computers[i].addr.domain:=1;
computers[i].addrp:=j;inc(j);
end;
j:=1;
for i:=35 to 38 do begin {router 7, domain 1}
computers[i].addr.router:=7;computers[i].addr.domain:=1;
computers[i].addrp:=j;inc(j);
end;
{------------- END OF INITIALIZATION PART -------------}
End;
Procedure Error(ErrorNum:byte);
Begin
textcolor(lightred);
writeln(' Error !');
case ErrorNum of
1: writeln(' One (or two) of above addresses are not exist');
2: writeln(' FROM and TO are same');
end;
readln;halt;
End;
VAR tmpStr :string;
tmpFrom :TAddr;
tmpTo :TAddr;
tmpData :string;
i,j :integer;
tmpX,tmpY:integer;
FromNum,ToNum:byte; {index FROM and TO computers in array}
BEGIN {------------- MAIN PROGRAM ---------------}
Initialization;
ShowGraphics(false);readln;CloseGraph;
ClrScr;TextColor(LightGreen);
write(' Global Network Emulation ');ShowTime(70,1);writeln;
{------------- ADDRESS AND DATA REQUEST ---------------}
Write(' Enter FROM address (X.X.X) : ');readln(tmpStr);{FROM request-------}
Val(tmpStr[1],tmpFrom.router,i);Val(tmpStr[3],tmpFrom.domain,i);
Val(tmpStr[5],tmpFromp,i);{target request-----------------------------}
Write(' Enter TO address (X.X.X) : ');readln(tmpStr);
Val(tmpStr[1],tmpTo.router,i);Val(tmpStr[3],tmpTo.domain,i);
Val(tmpStr[5],tmpTop,i);
Write(' Enter string-type DATA : ');readln(tmpData);
{------------- SEARCH 'FROM' TERMINAL -------------------}
for i:=1 to 38 do if
(computers[i].addr.router=tmpFrom.router) AND (computers[i].addr.domain=tmpFrom.domain)
AND (computers[i].addrp=tmpFromp) then FromNum:=i;
{------------- SEARCH 'TO' TERMINAL ----------------------}
for i:=1 to 38 do if
(computers[i].addr.router=tmpTo.router) AND (computers[i].addr.domain=tmpTo.domain)
AND (computers[i].addrp=tmpTop) then ToNum:=i;
if (FromNum=0) OR (ToNum=0) then Error(1);
if FromNum=ToNum then Error(2);{computer cannot send batch to itself}
{------------- FILL 'ADDRESS' FIELDS-----------------------}
computers[FromNum].mem.to_.router:=tmpTo.router;
computers[FromNum].mem.to_.domain:=tmpTo.domain;
computers[FromNum].mem.to_p:=tmpTop;
computers[FromNum].mem.from.router:=tmpFrom.router;
computers[FromNum].mem.from.domain:=tmpFrom.domain;
computers[FromNum].mem.fromp:=tmpFromp;
{------------- FILL DATA FIELDS-----------------------}
computers[FromNum].mem.data:=tmpData;
writeln;
OptPathPtr:=0;
if computers[FromNum].mem.from.router<>computers[FromNum].mem.to_.router
then routers[tmpFrom.router].CalcMinPath(tmpFrom.router,tmpTo.router);
OptPathPtr:=2;
WHILE TRUE DO BEGIN {-------------- GLOBAL NET SCANNING ------------------}
for i:=1 to 38 do {------scanning terminals for data for sending --------}
{} if computers[i].mem.data<>'' then begin
if (computers[i].addr.router=computers[i].mem.to_.router)
AND (computers[i].addr.domain=computers[i].mem.to_.domain)
AND (computers[i].addrp<>computers[i].mem.to_p)
then begin
computers[i].send(computers[i].mem);{into domain sending}
break;
end else if (computers[i].addr.router<>computers[i].mem.to_.router)
OR (computers[i].addr.domain<>computers[i].mem.to_.domain)
then computers[i].Send2Router(computers[i].mem); {send to router}
{} end;{if data for sending found}
for i:=1 to 7 do {------scanning routers for receiving data}
if routers[i].memory.data<>'' then begin
routers[i].receive(i,routers[i].memory);
if routers[i].memory.to_.router=i then begin {if send into domain}
routers[i].send2comp(routers[i].memory);
break;
end else begin
routers[i].send2nextRouter(routers[i].memory,i);
break;
end;
end; {-------------------------------}
for i:=1 to 38 do {------scanning terminals for receiving data}
if computers[i].mem.data<>'' then begin
if (computers[i].addr.router=computers[i].mem.to_.router)
AND (computers[i].addr.domain=computers[i].mem.to_.domain)
then begin {into domain receiving}
computers[i].receive(computers[i].mem,false);
break;
end; {---------------------}
computers[i].receive(computers[i].mem,true);{receiving from router}
break;
end;{if receive data found}
for i:=1 to 38 do
if (computers[i].mem.data<>'')
AND(computers[i].addr.router=computers[i].mem.to_.router)
AND (computers[i].addr.domain=computers[i].mem.to_.domain)
AND (computers[i].addrp=computers[i].mem.to_p)
then while true do begin {---------Batch received !---------}
HiddenCursor;
tmpX:=wherex;tmpY:=whereY;
ShowTime(70,1);
gotoXY(tmpX,tmpY);
if keypressed then begin
readkey;
ShowGraphics(true);
readln;
CloseGraph;
NormVideo;
NormalCursor;
halt;
end;
end;
tmpX:=wherex;tmpY:=whereY;
ShowTime(70,1);
gotoXY(tmpX,tmpY);
END;{-------------- END OF GLOBAL NET SCANNING ---------------------------}
END.