• No results found

Design and implementation of a simulator for a local area network utilizing an IBM PC/AT or compatible computer

N/A
N/A
Protected

Academic year: 2019

Share "Design and implementation of a simulator for a local area network utilizing an IBM PC/AT or compatible computer"

Copied!
125
0
0

Loading.... (view fulltext now)

Full text

(1)

Rochester Institute of Technology

RIT Scholar Works

Theses Thesis/Dissertation Collections

5-21-1988

Design and implementation of a simulator for a

local area network utilizing an IBM PC/AT or

compatible computer

Christian G. Midgley

Follow this and additional works at:http://scholarworks.rit.edu/theses

This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion in Theses by an authorized administrator of RIT Scholar Works. For more information, please [email protected].

Recommended Citation

(2)

Rochester Institute of Technology

College of Engineering

Department of Computer Engineering

Design and Implementation of a Simulator for a Local Area

Network Utilizing an IBM Pc/AT or Compatible Computer.

Christian G. Midgley, Sr.

May 21, 1988

An intern project, submitted to the Faculty of the College of

Engineering in Partial fulfillment of the requirements for the

Masters of Engineering Degree in Computer Engineering.

Approved by:

George A Brown

(3)

Abstract

Thepurpose ofthis projectisto provide afixturewhich maybe used as a

local area networkfor a course similarto the Small SystemsWorkshop course

(EECC756) as taught in the spring of 1986. This fixture will provide the

physical layerofthe local area network. This network would be Ethernet like

but use an RS-232C communication between the fixture and the nodes. In

additiontosimulating theetherthefixturewould provideforon-line analysis

of the packets being sent to provide feedback to the student as well as the

professor.

TheIBM PC/ATtype personal computer was selected as the hostforthe

fixturesinceit isa basicunit which isavailable atthe currenttime. In addition

it provided an excellent base operating system. The software that was

developed makes use of the direct system calls to the MS-DOS operating

(4)

Table of Contents

Abstract /

TableofContents

ListofTables ... . . . v/V

ListofFigures viii

1.0 Introduction ... 1

1.1 Goals ... 1

2.0 Fixture Description 2

2.1 Hardware Description .... 2

2.1.1 IBM PC/AT orCompatible Computer ... 3

2.1.2 Expansion CARD .3

2.2 Network Description 12

2.2.1 Header 12

2.2.2 SourceAddress 12

2.2.3 Destination Address 12

2.2.4 Packet Size ... 13

2.2.5 PacketType 13

2.2.6 Data 13

2.2.7 Checksum 13

(5)

Table of Contents

(cont)

2.3.1 Physical Interface 14

2.3.2 Data Format ... 14

3.0 Programming Environment ... 18

3.1 MS-DOS 18

3.1.1 CIs . 18

3.1.2 Copy ... .... .18

3.1.3 More . .19

3.1.4 Pause 19

3.1.5 Type . .19

3.2 MicrosoftC .... .... 19

3.2.1 Compiler .19

3.2.2 Linker ... 20

3.2.3 Make 20

4.0 TestMethod. ... .21

5.0 Discussion ofResults ... 22

6.0 Code. ... 23

(6)

Table of

Contents

(cont)

6.2 Init b.c Init b() 35

6.3 Pfile.c Print file() 37

6.3.1 Print fileO 37

6.3.2 ScreenQ 39

6.3.3 ComQ 40

6-3.4 Lpt()

.41

6.4 Net_sup.c .... 42

6.4.1 ProcessO

... 42

6.4.2 Outerr() .... 49

6.4.3 Shut down() 52

6.4.4 Rsam() .... 54

6.4.5 Psam() 55

6.4.6 Packet_check() .... 55

6.5 Menu.c Menu() .... 59

6.6 Misc.c 61

6.6.1 Center() 61

6.6.2 GetlineO ... 62

6.6.3 Help() 63

6.6.4 lnit() . ... 65

6.6.5 GetoneO ... ... . . 65

(7)

Table of Contents

(cont)

6.7 Phead.c PrintheadO 68

6.8 Rnet.c 70

6.8.1 Run_net() 70

6.8.2 EcheckO .... ... 76

6.8.3 Port_reset() 77

6.9 SetMat.c SetmatO 78

6.10 S_par.c ... 80

6.10.1 Set_parms() .... ... 80

6.10.2 Set_sd() 88

6.10.3 Sort_sd() 89

6.10.4 Port_parms() 89

6.11 Include.h 96

6.12 Defines.h ... .... 97

6.13 Proj 99

6.14 Help Files 101

6.14.1 NetsimO.hlp 101

6.14.2 Netsiml.hlp ... 102

6.14.3 Netsim2.hlp ... .... 103

6.14.4 Netsim3.hlp 104

(8)

Table of

Contents

(cont)

6.14.6 Netsim5.hlp 106

6.14.7 Netsim8.hlp 107

6.14.8 Netsim9.hlp . . 108

6.14.9 NetsimlO.hlp ... 109

6.14.10 Netsim11.hlp .... .110

AppendixA References A-1

Technical Manuals .... A-2

(9)

List of Tables

2.1 Bill ofMaterial 10

2.2 Port Addresses

. . 11

(10)

List of Figures

2.1 Expansion Card Bus Interface & Address Decode 4

2.2 Expansion Card RTS Port & ProgrammableBaud Clock 5

2.3 Expansion Card Port Selection ... .6

2.4 Expansion Card Modems & Output . ... .7

2.5 Expansion Card Rx Available .... 8

2.6 Expansion CardComponent Location 9

2.7 Packet Description 12

2.8 Data Format .16

(11)

1.0 Introduction

The idea for this project came from the EECC756 (Small Systems

Workshop) course which I completed in the Spring of 1986. This course

included a laboratory which wascompound bythe lack of afixture on which

todevelopthe network nodes. Asa resultI undertookthis projecttodevelop

a tool to aid in the understanding of the workings of Local Area Networks.

This project will integrate both hardware (the interface PWBA) and software

(thecoderunning ontheIBM PC/ATorCompatibleComputer).

1.1 Goals

The single goal of this project was to provide a fixture which could be

used asan educational tool to provide a controlled simulation ofa Local area

network. This goal was achieved by utilizing a straight forward

communication device to be controlled by a host which required very little

expertise to operate. The communication of the nodes uses a simple and

straightforward protocol (serial ascii over an RS-232C protocol). In addition a

(12)

2.0 Fixture Description

The fixture would be constructed using an IBM PC-AT or Compatible

Computer as the host. An expansion card and a remote connection box

would provide the interface to the nodes. The expansion card will allow for

programmable distances betweenthe nodes, compilation ofnetwork activity

to theterminal, printing ofsummary information to a printer, and control of

generatingerrors in thedataatvaried rates. The DB-25 connectorforeach of

the eight network portsis located in a connection boxwhich isexternal to the

host PC. Thisconnection box is linked to the simulatorPWBA via a fortywire

cablewhich allows fora five wire interface on each ofthe ports. Thesewires

areTxD, RxD, CTS, RTS,andsignal ground.

The RTS line of each port is ORed with a bit of the RTS register which

allowsforsimple softwarecontrol ofthesesignals. The baud, numberofdata

bits, number of stop bits, parity enable and odd/even parity are

programmable by the user. Each port on the card has a pair of I/O addresses

which are used forcommand and data access. An additional output address

pair isallocated fora global write of commands and data to all ports at the

sametime.

2.1 Hardware Description

(13)

1). An IBM PC/ATorCompatibleComputer,and

2). An Expansion Card foritem 1 togetherwith an extended connection

box.

2.1.1 IBM PC/ATorCompatible Computer

The computer is a standard purchased item which is common both in

educational facilities as well as in industry so no further description is provided.

2.1.2 Expansion Card

The Expansion Card consistsof several key Items.

1). EightIntel 8251 A PROGRAMMABLE COMMUNICATION INTERFACE.

2). EightMC145406 MODEM CHIP

3). APXO-768 PROGRAMMABLE 768K CRYSTAL OSCILLATOR

In addition to the key items the Expansion Card contains various

(14)

>

in

+

AAA

0)

ac cc cr cc rr c c c o O O

aaaa. a. a. (/i a

-r> rr> *T i/i

AAAAA r^^oi/i^-mrM. o ra

22?

Hi'

+ AAAA

fN i/i rN m

tU cu <U cu

li Cg oj cu .C .C -C

O

r-to u-> ^ >> > >

m fN ^

<i. n 5

o <

:A

00 A ro D > 55 IO

R

/SHi'

nj cn T < < < <

" rsj m <T

< < < < rN fN <N fN

U

onto

< "

(Jj CU <U Dj CU <U .c .c .c

g o o

Hi

t- rsi m t

-fM

t- t * < r\i rvi

<T <-fN <<<<<<

ll'

<

^tj

* < <

Hi'

< CO DC icnl 0(j'-rNm^fLnior^OO 0QCOCQ0QCQCO0C1QQ <<<<<<<<

^

ll'

inm <J w o

o * in m

^ ui us n co cn ^c 0<-rMm^iniJ3N

(15)

u O _i u 6 ID < ca > in + WO 01 3 o co 3 ro ~4' in cc CQ

n tnj in a n

//////// LT) + O en aaaaaaaa O nQQQQQQQQ IL CM DC a <: 3 o < _i CO 1/1 ZD CO < < a a; 01 LOcn co cn > CO + o rsi oaoooocro

1

cn o

'-

I-0 O <:

0. O

(16)

^f ** "a-

<3-in

M -M +- -M +^

QJ QJ (U Hf D Of O Q) 11 V

-C.c .c .c j:

i/i toin i/i i/i

00 00 00 CO GO

Q Q K l/l V

OQDQQQQQxx|-fc 3-0= I- ^ ^ x

l/> ID

< I-<

o i^ i: i:

00

a: 4i w u u 5 Q ^1 ^ x X

~

-a: u r: !r

O

< 2 2

cch-v

0 < sd

HI-u O cau

"^ ^ v +,

*-<u (ll 01 1) 01 Ol ai au 01 01 01 Ol

.c c.

C"

(17)

Q Q ^ QQ^lo

n*wnias.PB"

J*3|-fN TY

|N|fNlie IN IN

li*

u Q > us

$K

fCT.

in*N n

^ . jEF

NlrslfNr\ in vilpr

(18)

I/)

GO.

<

1.1

CO

u

tf

u 1

>

1 1 1

> ,_l*~~

-rr r-.|ld|ro|

LO

-~t\fn^^(Mm^ + >>->->->->->->-<-^^<-(\NM)N o

<N

(M M

3

^rv|<-^^^[\fNNfN Z

cn <N

"3-CO oo ^~ ro IO r^

cm ro tf us CO r^ CO

(0 (0 (Z (*} "(0 (0 ro "H? > > > > > > > >

ID < < < < < < < <

X X X X X X X X CC CC cc cc cc cc cc cc

^

LO oi

ch

(19)
(20)

BILLOF MATERIAL

Component Device Description

U1 74LS00 QUAD2 INPUT NAND GATE

U2-3 74LS138 ONE-OF-EIGHTDECODE/DE-MULTIPLEXER

U4-6,17 74LS32 QUAD 2 INPUTOR GATE

U7.16 74LS374 OCTALD FLIP-FLOP,3-STATE

U8-15 MC145406 MODEM CHIP

U18-19,22 74LS244 OCTALBUS LINE DRIVER, 3-STATE

U20 74LS245 OCTAL BUSTRANSCEIVER, 3-STATE

U21 PXO-768 PROGRAMMABLE768K CRYSTALOSCILLATOR

U23-24 74LS08 QUAD 2 INPUT AND GATE

P1-8 8251A PROGRAMMABLE COMMUNICATION

INTERFACE

(21)

ADDRESS MAP

30FH P1 COMMAND REGISTER

30EH P1 DATA REGISTER 30DH P2 COMMAND REGISTER

30CH P2 DATA REGISTER

30BH P3 COMMAND REGISTER

30AH P3 DATA REGISTER 309H P4 COMMAND REGISTER

308H P4 DATA REGISTER

307H P5 COMMAND REGISTER

306H P5 DATA REGISTER

305H P6 COMMAND REGISTER

304H P6 DATA REGISTER

303H P7 COMMAND REGISTER

302H P7 DATA REGISTER

301H P8 COMMAND REGISTER

300H P8DATA REGISTER

31EH U7RTS-BUS LATCH

31CH U22RxAVAILABLE PORT

31AH U16 BAUD RATE LATCH/PORT RESET

319H P1-8 COMMAND REGISTER (ACCESSESALL8PORTS, WRITEONLY)

(22)

2.2 Network Description

The network would be similar to ethernet in its protocols. The main

exception isthe useofthe RS-232Cprotocol forcommunicationsbetweenthe

network andthe nodes. Thefollowing isa listofthespecificationswhich will

be required bythe network.

Packet Description

A A B C D E DATA

//

F F F F

ft

Fig. 2.7

2.2.1 Header(A) The header will consist of 2 Bytes. The value forthe

byteswill be 55H. Thisvalue is being used instead of

AAH so as to enable multiple numbers of data bits

withinthe RS-232C protocol.

2.2.2 SourceAddress(B)The source address will be the third byte of the

packet and is set to a number between 0 and 7

representing the portnumberofthesourcenode.

(23)

byteofthe packet and besettoa numberbetween 0

and 7 representing the port number of the

destination node.

2.2.4 PacketSize (D) The packet size will occupy the fifth byte of the

packet and show the size ofthe entire packet. This

valuewill includethe 10 bytes described hereand be

in the form of an unsigned value 0-126 which will

indicate 1 lessthan theactual size.

2.2.5 Packet Type(E) The sixth byte ofthe packetwill indicate the type of

packet. Thevalidtypesare:

1, Data

2, Ack

3, Nack

2.2.6 Data The seventh thru one hundred twenty third (123)

bytes of the packet are available to the individual

nodesto be utilized in any mannertheyseefit.

2.2.7Check Sum(F) The Last 4 bytes ofthe packet will be allocated as a

check sum. The network will not check the value of

the check sum so the student can choose any

(24)

2.3 Interface Specification

The interface specified for this fixture is that of RS-232C with standard

serial communication. See the following sections for details of the physical

specifications and data format.

2.3.1 Physical Interface

Asstated abovethe physical interfaceofthefixture isa 5wireversion of

RS-232C, which meansthatthe data is exchanged on two data lines. One of

the data linesissetto transmitdata to the nodewhile the otheris receiving.

This data transfer is full duplex, meaning that transmission and receive can

occur at the same time. The voltage levels are per the standard, ie a data

"zero"

is indicated bythe presence of between +3Vdc and + 15Vdcwith the

fixture using a nominal +12Vdc, while a data "one" is indicated by the

presence of between -3Vdc and -15Vdc with the fixture using a nominal

-12Vdc.

In addition to the data linesthere are two lines, a RTS (request to send)

lineand a CTS (cleartosend) line. These lines are used todeterminethe state

of the node to fixture interface. If the CTS line is active then the fixture

knowsthat there is a node on the line. The RTS line is used by the fixture to

indicateto the node ifthe network is busy. It isthru this requestto send line

thatcollisionsare minimized.

The final line issignal groundwhich needsnoexplanation.

(25)

The data format is programmable by the user of the network, the followingtable (Table 2.3) showsthevarious possibledata formats.

Data FormatConfiguration Selection

ITEM POSSIBLECONFIGURATIONS

Stop Bits 1. 15. 2

Data Bits 5, 6, 7, 8

Parity Enabled orDisabled

If Enabled, Odd orEven

Baud Rate 1200, 2400, 4800. 9600

Table 2.3

(26)

Data Format

Stop Bit(s)

Data Bits

When enabledthe paritybitistheend ofthedatasection.

(27)

Configuration of Network as Tested and Demonstrated

Standard TTY

Terminal

IBM PC/ATor

CLONE

Simulator PWBA isplaced in an I/OslotofPC#1.

(28)

3.0 Programming Environment

The environment that was picked for this fixture was that of the IBM

PC/ATor Compatible. Thisenvironmentwas picked for several reasons. The

most important of these reasons were, 1) the availability of a host both at

work aswell as in the school lab., and 2) the availability ofa C compiler for

thiscomputer.

3.1 MS-DOS System Calls

In order to both simplify the programming task as well as to ensure

greater reliability several functions were implemented as direct MS-DOS

System callsthefollowing isa listofthecalls with a shortdescription.

3.1.1 CLS

The MS-DOSCLScommand hastheaction ofclearingthe console screen.

It takesno arguments, isan Internal typecommand and has a simple syntaxof

"CLS".

3.1.2 COPY

The MS-DOS COPYcommand hasthe action ofcopying a sourcefileto a

destination file. Ittakesone ortwoargumentsa sourcefile and an optional

destination file. It isan Internaltypecommand and is being used to copy the

(29)

data file. Therefore the syntax for this command is "COPY <filename>

<printer port>.

3.1.3 MORE

The MS-DOS MORE command hasthe action ofdisplaying a full screen

ofdata and then waiting fora userresponse before continuing. It isused by

redirecting the outputof a command such astype (see 3.1.5)to its input. It is

an external type command and is being used in the following syntax "TYPE

<filename>JMORE".

3.1.4PAUSE

The MS-DOS PAUSE command hasthe action of suspending execution

untilthe usertypesa key. It hasasimple syntaxof "PAUSE".

3.1.5TYPE

The MS-DOS TYPE command has the action of displaying a file to the

console screen. It is an internal type command and has the syntax of "TYPE

<filename>".

3.2 MicrosoftC

The Microsoft C Compiler was picked to compile and link the software

forthis projectmainly because of its availability and my previous knowledge

ofthiscompiler.

(30)

The Microsoft C Compiler takes a normal C source code file and

produces a relocatable object code file. Although there are

many options

available, for most programs including this one, the standard options are sufficient.

3.2.2 Linker

The Microsoft C Linker takes as input one or more object files. These

files could have been compiled by the C compiler or assembled by a

compatible assembler. In the case ofthis project all ofthe object files were

compiled bythe MicrosoftCcompiler. As inthe compilerthe linker has many

optionsbut forthis projectthe standarddefaultoptions were used.

3.2.3 Make

Microsoft C includes a facility called MAKE. This program isa software

control program. In other words it uses the date and time stamps on the source and object files as well as the final executable file and determines

which filesmust becompiled and or linked in orderto havethe latest revision

source contained in the executable version. This facility relieves the

programmer of the task of determining which source files have been

modified sincethe lastcompileand link. (See 6.13fora sampleofthe control

(31)

4.0 TestMethod

Afterthe PWBA was wire wrapped itwasfirst necessary to determine if

certainfunctionswere operation correctly. The firststepwas to determine if

any ofthe addresses could be accessed. The RTS Register and the Baud Port

were chosen asthey were thesimplestto verify operation on. Various values

werewrittenthe these portsto verifyproperoperation.

The nextstep wasto verify the operation ofthe oscillatorchip at all of

thefrequencieswhich wereto be used. Next the chipselect

and I/O ReadAWrite pinsof each portwere verified to be properly decoding.

After these diagnosticchecks were preformed a TTY terminal was connected

and the PC placed in the DEBUG modeto verify read and writeto each ofthe

ports as well asthe command values to be used in the programming of the

8251's. Atthis point a seriousflaw was noted. Attimesthe chips were in an

improper mode and could need resetting which would not always work. A

signal was added totheexpansion card via an unused bitin thebaud register.

Thissignal replaced the PCresetsignal tothe 8251'sand allowedforsoftware

controlled hard reset orthe ports.

Finallya program waswritten forthe second PCto send valid packetsto

the network. This program along with the TTY terminal allowed for full

testing of the network management code, and is the configuration which

(32)

5.0 Discussion ofResults

The results ofthe project were very favorable. The network can easily

handle and determine the accuracy of packets that are sent from node to

node. Collisionscan be detectedand reportedto the user. Thesingle lacking

test ofthe network was thatof having the full eight nodes trying to send as

many packets as possible, but the nature of the beast leads one to believe

that with propercode running on the eight nodesthere is a great possibility

forsuccess. Since this project was developed as a teaching aid for a network

course itwill be interestingto seewhat kind of modifications can be made by

future students.

Probably the single most important factor of this project is that ofthe

knowledge of the innerworkings ofthe IBM PC/AT. The knowledge gained

from completing this project has alreadybeen putto use in thework place. I

have designed code which converts the PC into several different types of

controllers aswell asdataacquisition modules.

This project has also allowed me to grow and develop a stronger

(33)

File NETSIM.C May 18, 1988 11:07 AM

6.0 Code

Thefollowing pages are a complete listing ofthesource code forthis

project. The actual code fromthe PCfileswill beshown in italic.

6.1 Netsim.c

The Netsim.cfile containsthe Main function which is compiled asthe

starting pointofthe code.

FILE NETSIM.C

Network Simulator

Written by: ChrisMidgley

Datewritten: 10/6/87

Datelastrevision: 51 11/88

Thissoftwareiswritten as the controllingsoftware foraproject to design

local area network simulator. This simulator was designed as part of the

requirements for the Master of Engineering Degree in the Computer

EngineeringDepartmentatthe Rochester InstituteofTechnology.

The software of this project is written in several modules. Proj.c is the

mainmodule. Theothermodulesaredefined below.

INCLUDE.H

Thisfile containsthe requiredincludefilesaswellastheexternal

(34)

File NETSIM.C May 18, 1988 1 1:07 AM

DEFINES.H

This filecontainsthe declarationsofthe various constants used within

themodules.

INIT_B.C

This files contains the function init_b() which initializes the baud

frequencygeneratorto thedefault baudrateasdefined in defines.hbythe

constantBAUD_RATE.

PFILE.C

Thisfilecontainsthefunctionprint__file which will causethedata

filetobeclosed,printed and reopenedforappend.

NET_SUP.C

Thisfilecontains thefollowing functions:process(c), outerr(port,c),

shut__down(port), rsam(),psam(port,andval), packet_check(). These files perform various supporttypefunctions.

MENU.C

Thisfile containsthe function menuQwhichcontrolstheprintingof

themain menuaswellasreturning theselection.

MISC.C

Thisfile containsthe following functions: center(s), getline(s),

help(num), initQ, getoneQ, check_end(). Thesefunctionsalso areofa

support nature.

PHEAD.C

This filecontainsthefunctionprintheadQ. Itisusedtoprintthe

headingto themenu.

(35)

NieNblSIM.C May 18, 1988 11:07 AM

Thisfile containsthe functions: run net()andecheckQ. Run net()is

thefunction which actuallyrunsthe interfacebetween the8nodes. Echeck

istherandom errorgenerator.

SETMAT.C

Thisfilecontainsthe functionsetmat(dist)whichsetsup thedistance

matrixusedinshuttingdownnodes.

S_PAR.C

This file contains the functions set_parms(), set sd(), sort sd(i)

whichareusedtosetup thenetworkparameterssuch asbaudanddistances.

*************************************************************** /

#include <stdio.h>

^include <string.h>

#include <conio.h>

#include "defines.h"

I*

The following global variables are used to simplify the passing of many

extra parameters. They were chosen for specific reasons and are only

modified at specific pointsin theprogram.

fpwisaglobalpointerto the tracefile.

filenameisusedasaplacetostoretheMS-DOSname ofthe trace file.

optionisusedasautilitystringandis declared globallytoreduce the

(36)

File NETSIM.C May 18, 1988 1 1:07AM

model and mode2 are used for command and mode instructions to the

825Vs.

baud__valisthecurrent value usedtosetthe 8251's. Itissetasdefined

bytheconstantsin include.h.

baud_rateistheintegervalue ofthebaudi.e. 9600,4800.

error rate isthe inverseofthe error percentage. Itisusedin the error

generationbyperformingthe modulusfunctionon therandomnumber.

sdmatanddist mat are usedindetermining thenetworktopology.

*/

FILE*fpw,*fopen();

charfilename[32],option[32];

unsignedchar mode1,mode2;

intno_errors,baud_val,baud_rate,error_rate,sdmat[8][8][2],dist_mat[8][8];

main(argc,argv)

intargc;

char* argv[];

{

intopt;

intacount,i,h;

I*

initializethenetwork */

initQ;

init_b();

model =MODE1;

mode2=MODE2;

systemC'ds");

acount=argc;

I*

(37)

File NETSIM.C May 18, 1988 11:07 AM

if(acount= =1)

{

I*

promptfora data file */

printheadQ; I*printheadermessage*/ printf("

Enterthedata fileto use ");

getline(filename);

} else

I*

elseifmorethan one argument promptforproper usage and exit*/

if(acount> 2)

{

printf("%s: usage: %s[<filename>]\n",argv[0],argv[0]);

return(-1);

}

else

I*

else makea copyofthe commandline filenamein theglobalvar. filename

*l

strcpy(filename,argv[1]);

I*

set-up the timerfor1 mSec. timing*/

outp(TIM_CONT,TIM_MODE);

outp(TIM_P2,TIM_LOW);

outp(TIM_P2,TIM_HIGH);

outp(TIM_WR,TIM_START);

I*

loop untilan exitconditionsetsi to0 */

i= i;

(38)

File NETSIM.C May 18, 1988 1 1:07 AM

while (1) {

I*

ifnullfilenameprompt asinvalidand getanewfile name */

if(filename[0] = = \n')

{

system("cls");

printf("\n\n\n\nlNVALID FILE NAME RE-ENTER ");

getline(filename);

}

else

break;

}

I*

iffilenameisa ?, display helpelse testiffile exists. Iffileexists

thenpromptforaction i.e.append, overwrite, rename, exit. Ifthe file doesnot existthen open forwrite. */

if(!(filename[0] = ='?'))

<

if(acount= =1)

filename[strlen(filename)-1]=\0';

acount= 1;

strcat(filename, ". dat");

if((fpw=fopen(filename,"r")) I= NULL) {

systemC'ds");

printf("\n\n************************\n\nfile %s already

exists\n\nEnteroption\n(a)ppend, (r)ename, (o)verwrite, or(e)xit "filename);

option[0]=getoneQ;

fclose(fpw);

if (option[0]= = 'q'

Hoption[0]= ='Q')

{

(39)

FileNETSIM.C May 18, 1988 1 1:07AM

fclose(fpw);

systemC'ds");

exitQ;

}

h = 1;

while(h)

{

switch(option[0])

{

case

'?'

:

help(1);

printf('\n\n***********************

*\n\nfile %s

alreadyexists\n\nEnter option\n(a)ppend, (r)ename, (o)verwhte, or(e)xit

"filename);

option[0]=getone();

break;

case V:

case'R':

systemC'ds");

printf("\n\n\nEnterthe data filetouse ");

getline(filename);

h=0;

i= 1;

break;

case 'a '

:

case 'A':

h=0;

if((fpw=fopen(filename,"a")) I= NULL)

i=0;

else

{

(40)

FileNETSIM.C May 18, 1988 1 1:07AM

printf('\n\n\nCould not open %s\n"filename);

printf("\n\n\nEnterthe data file touse "); } break; case 'o' : case 'O' : h=0;

if((fpw=fopenffilename,"w")) ! = NULL)

i=0;

else

{

systemC'ds");

printf('\n\n\nCouldnot open %s\n"filename);

printf("\n\n\nEnterthedata fileto use ");

} break; case 'e' case '' case 'q' case 'Q' systemC'ds");

if (check endQ)

{ h=0; fflush(fpw); fdose(fpw); systemC'ds"); retum(O); } else { h=0; i=1;

(41)

File NETSIM.C May 18, 1988 1 1 :07AM

get//ne(7/7enamej;

systemC'ds");

}

break;

default : h = 1;

systemC'ds");

printf("

INVALIDOPTION\n");

prjntf('\n\n************************\n\nfile %s

alreadyexists\n\nEnteroption\n(a)ppend, (r)ename, (o)verwrite, or(e)xit "filename);

option[0]=getone();

break;

} }

}

else

{

if((fpw=fopenffilename,"w")) /= NULL)

i=0;

else

{

systemC'ds");

printf("\n\n\nCould notopen %s\n",filename); printf("\n\n\nEnterthedata file to use ");

getline(filename);

} } }

else

{

help(O);

(42)

File NETSIM.C May 18, 1988 11:07 AM

systemC'ds");

I*

loop thru menu andperform the requestedaction */

do

{

opt=menu();

systemC'ds");

switch (opt)

{

case 'q':

case 'Q':

case 'e':

case 'E':

if(check end()) {

fflush(fpw);

fdose(fpw);

systemC'ds");

return(l); }

else {

systemC'ds"); }

break;

case '?':

help(2);

break;

case 's':

case 'S':

(43)

File NETSIM.C

May 18, 1988 1 1 :07AM

{

if(check_end()) {

fflush(fpw); fdose(fpw);

systemC'ds");

retum(l);

}

else

{

systemC'ds");

} } break;

case 'p':

case 'P':

if(0=print_file(filename)) = = -1)

{

fflush(fpw); fdose(fpw);

if(check_end())

{

fflush(fpw);

fdose(fpw);

systemC'ds");

return(1);

}

else

{

systemC'ds");

} } break;

(44)

File NETSIM.C May 18, 1988 11:07AM

case '/?';

if((i=

run_net()) = =

-1)

{

fflush(fpw); fdose(fpw);

if(check endQ)

{

fflush(fpw);

fdose(fpw);

systemC'ds");

return(l);

}

else

{

systemC'ds");

}

}

if(i = = -2) {

systemC'ds");

printf("NETWORKFAILURE RETURNINGTOMENU\n");

}

break;

default:

printf("INVALID OPTIONXn");

break;

} }

while (opt);

(45)

FileINIT B.C May 18, 1988 1 1:06AM

6.2 lnit_b.c

Thisfile containsthefunction INIT Bwhich isused tosetup the

programmable crystal oscillatorto the correctfrequency.

FILEINIT_B.C

Network Simulator

Written by: ChrisMidgley

Datewritten: 10/6/87

Date lastrevision: 51 1 1/88

Thissoftware iswritten asthe controllingsoftware fora projecttodesign

local area network simulator. This simulator was designed as part of the

requirements for the Master of Engineering Degree in the Computer

EngineeringDepartmentatthe Rochester InstituteofTechnology.

This function is called during initialization to set the system baud rate to

thedefaultvalueasdefinedbytheconstantBAUD RATEin defines.h. This

function sets the oscillator port with the correct frequency for the selected

baudrate.

***************************************************************/

#indude "indude.h"

init_b()

{

(46)

File INIT B.C May 18, 1988 1 1:06AM

i =BAUD_RATE;

switch(i)

{

case 1200 :

baud_yal=B1200;

outp(BAUD_PORT,B1200R);

outp(BAUD_PORT,B1200);

break;

case2400 :

baud =82400;

outp(BAUD_PORT, B2400R);

outp(BAUD_PORT, B2400);

break;

case4800 :

baud_val=B4800;

outp(BAUD_PORT,B4800R);

outp(BAUD_PORT, B4800);

break;

case 9600:

baud_val=B9600;

outpfBAUD_PORT,B9600R);

outp(BAUD_PORT,B9600);

(47)

File PFILE.C May 18, 1988 11:05 AM

6.3 Pfile.c

Thisfile containsthe functionsprint file,screen, comand Iptwhich are usedtoeitherdisplaythecurrent contentsofthedata logfileto thescreen or

tocopythem toa printerhooked to theserial or parallel portofthe computer.

6.3.1 Print_file

Thisfunction overseesthedisplayorprinting ofthedata file. It takes careofclosing, thecalltodisplayor print,and reopeningthedata file for append.

FILE PFILE.C

Network Simulator

Written by: ChrisMidgley Datewritten: 10/6/87 Datelastre vision: 5/11 188

Thissoftware is written as the controllingsoftware foraproject to design a local area network simulator. This simulator was designed aspart of the requirements for the Master of Engineering Degree in the Computer

EngineeringDepartmentatthe Rochester InstituteofTechnology.

This function causes the data file to be printed to eitherthe coml, com2, Ipt1,Ipt2 orthescreen. Itfirstflushesthe file, then closesit, makesa MS-DOS

system call toprint or displayand finally reopen thedata file in the append

(48)

File PFILE.C May 18, 1988 1 1:05 AM

***************************************************************/

#indude"indude.h"

print_file(filename)

char* filename;

{ charc; fflush(fpw); fdose(fpw); systemC'ds"); printf('\n\n"); while(1) {

printf('\n\n\n\n\n PRINT SUB-MENU\n\n");

printf("

(S)creen\n\n (C)om\n\n (L)p1\n\n (E)xi1\n\n

Enteroption: ");

while(1)

{

if(kbhit())

{

c=getch();

break; } } switch(c) { case 'S' : case 's' : screenQ;

fpw=fopen(filename, "a");

systemC'ds");

return(1);

case 'c'

(49)

File PFILE.C May 18, 1988 11:05 AM

case 'C:

com();

fpw=fopen(filename,"a");

systemC'ds");

return(1);

case V;

case'L':

lpt();

fpw=fopenffilename,"a");

systemC'ds");

return(1);

case 'e'

:

case 'E'

:

fpw=

fopen(filename,"a");

systemC'ds");

retum(l);

default:

systemC'ds");

printf('\n\n INVALIDOPTION \n");

break; }

} }

6.3.2Screen

Thisfunction causesthedata file tobe displayed to thescreen.

screenQ

{

(50)

NlePFILE.C May 18, 1988 11:05 AM

systemC'ds");

strcpyfs,"type ");

strcat(s,filename);

strcatfs,"

Imore");

system(s);

system(" pause");

}

6.3.3Com

Thisfunctioncausesthedata fileto be printedtotheserial port ofthe host.

com()

{

chars[128],s2[2],c= 'Q';

strcpyfs,"copy ");

strcpy(s2,"0");

strcat(s,filename);

while((cI = '1')&&(c!= '2')) {

printf(" PORT 1 or2 ");

c=getch();

if((c!= '1')&&(c!= '2'))

printf("INVALIDPORT");

}

s2[0]=c;

strcatfs, "

com");

strcat(s,s2);

printf("%s\n",s);

system(s);

(51)

i-ne PFILE.C May 18, 1988 11:05 AM

6.3.4 Ipt

Thisfunction causesthedata file tobe printedtothe parallel portofthe

host.

IptO

{

chars[128],s2[2],c='0';

strcpy(s,"copy ");

strcpy(s2,"0");

strcat(s,filename);

while ((c!= '1')&&(c!= '2'))

{

printf ("

PORT1 or2 ");

c=getch();

if((c!= T)&&(c!= '2'))

printf("INVALIDPORT--");

}

s2[0J=c;

strcat(s,"

Ipt");

strcat(s,s2);

printf("%s\n",s);

system(s);

(52)

EileNET SUP.C May 18, 1988 11:05AM

6.4 Net sup.c

The Net sup.c contains variousfunctionswhich supporttheoperation

ofthe network. Theyarediscussed insections6.4.1 thru 6.4.6.

6.4.1 Process

Thefunction process is usedto "process" eachcharacterthatis received.

Itdeterminesifa collision hasoccurred and ifan error isto beinduced it

inducesthaterror.

/*************************************************************,,.* FILENET_SUP.C

Network Simulator

Written by: ChrisMidgley

Date written: 10/6/87 Date lastrevision : 5111/88

This software is written as the controlling software for a project to designa localarea networksimulator. Thissimulator wasdesignedas part of

the requirements for the Master of Engineering Degree in the Computer Engineering Departmentatthe Rochester InstituteofTechnology.

The functions in this file are support functions for the run net() function.

***************************************************************/

^include "indude.h"

#define TIME_OUT2000

I*

(53)

File NET SUP.C May 18, 1988 1 1:05 AM

externlong intstime;

externlong inttime_out;

extern intmake_error,pn,cur_port,lpc,collision,longerr,ccount,pacsize;

extern unsignedcharpacket[515];

This function processes each character received to determine if a

collision occurs or if any other problem exists. It files the character into the

variablepacket.

***************************************************************/

process(c)

unsignedcharc;

{

unsignedcharch;

ccount+ +;

if(ccount= = 12<S<& make error)

{

printfC********

NETWORK INDUCEDERROR********\n");

fprintf(fpw,"********NETWORK INDUCED ERROR* *******\n");

}

switch(c)

{

case 1:

ch=inp(PORT1);

iffccount = = 128t& make_error)

outerr(PORT1,ch);

else

outp(PORTA,ch);

break;

case2:

ch=inp(PORT2);

(54)

FileNET SUP.C May 18, 1988 11:05 AM

outerr(P0RT2,ch);

else

outp(PORTA,ch);

break;

case4:

ch=inp(P0RT3);

iffccount = = 12 && make error)

outerr(PORT3,ch);

else

outp(PORTA,ch);

break;

case 8:

ch=inp(P0RT4);

if(ccount = = 12&&make error)

outerr(P0RT4,ch);

else

outp(PORTA,ch);

break;

case 16:

ch=inp(P0RT5);

if(ccount = = 12&&make_error)

outerr(PORT5,ch);

else

outp(PORTA,ch);

break;

case32:

ch=inp(P0RT6);

iffccount = = 12&& make_error)

outerr(PORT6,ch);

else

outp(PORTA,ch);

break;

case64:

(55)

File NET SUP.C May 18, 1988 11:05 AM

if(ccount = = 12 &&make error)

outerr(PORT7,ch);

else

outp(PORTA,ch);

break;

case 128:

ch=inp(PORT8);

iffccount = = 12 &&make error)

outerr(PORT8,ch);

else

outp(PORTA,ch);

break;

default:

if(! collision)

{

ch=0;

printf("\ncollision betweenports ");

fprintfffpw,"Vicollision betweenports ");

if(c&1)

{

ch'=inp(PORT1);

printfC'1 ");

fprintf(fpw,"1 ");

} if(c&2)

{

ch'=inp(PORT2);

printf("2 ");

fprintf(fpw,"2 ");

} if(c&4)

{

ch=inp(PORT3);

(56)

File NET_SUP.C

May 18, 1988 11:05AM

fprintf(fpw,"3 ");

}

if(c&8)

{

ch"

=inp(PORT4);

printf("4 ");

fprintf(fpw,"4 "); }

if(c&16)

{

ch =inp(PORT5);

printf("5 ");

fprintf(fpw, "5");

}

if(c&32)

{

=inp(PORT6);

printf("6 ");

fprintf(fpw,"6 ");

}

if(c&64)

{

=inp(PORT7);

printf("7 ");

fprintf(fpw,"7 ");

}

if(c&128)

{

ch =inp(PORT8);

printf("8 ");

fprintfffpw,"8 ");

} }

(57)

File NET_SUP.C May 18, 1988 11:05 AM

fprintf(fpw,'\n");

outp(PORTA,ch);

retum(1);

}

if(c!=cur_port)

{

if(! collision)

{

ch=0;

printf("\ncollision betweenports ");

fprintf(fpw,"\ncollision betweenports ");

if(cur_port&1 Hc&1)

{

=inp(PORT1);

printfC'1 ");

fprintf(fpw,"1 ");

}

if(cur_port&2Hc&2)

{

=inp(PORT2);

printf("2 ");

fprintfffpw,"2 ");

}

if(cur_port&4Hc&4)

{

=inp(PORT3);

printf("3 ");

fprintfffpw,"3 ");

}

if(cur_port&8Hc&8)

{

ch*=inp(PORT4);

printf("4 ");

(58)

FileNET_SUP.C May 18, 1988 11:05AM

;

if(cur_port&16ljc&16)

{

ch*

=inp(PORT5);

printf("5 ");

fprintf(fpw,"5 ");

}

if(cur_port&32//c&32) {

=inp(PORT6);

printf("6 ");

fprintf(fpw,"6 ");

}

if(cur_port&64//c&64)

{

=inp(PORT7);

printf("7 ");

fprintf(fpw,"7 ");

}

if(cur_port&128//c&128)

{

ch=inp(PORT8);

printf("8 ");

fprintf(fpw,"8 ");

} }

printf('\n");

fprintf(fpw,'\n");

outp(PORTA,ch + 1);

return(1);

}

packetfccount-1]=ch;

(59)

i-neNET_SUP.C May 18, 1988 11:05 AM

6.4.2 Outerr

Thefunction Outerrcausesthepropercharacterto beechoed to the

sending unitbutan errorto besentto all othernodes. Theerroris simplythe

character received plusone.

/***************************************************************

This functioncauses a characterto besenttoallports incorrectlyexcept for the port which sent it. It simulates an error happening during the

charactertransmission.

***************************************************************/

outerr(port,c) intport;

unsigned charc;

{

switch(port)

{

casePORT1 :

outp(PORT1,c);

outp(PORT2,c+ 1);

outp(PORT3,c+ 1);

outp(PORT4,c+ 1);

outp(PORT5,c+ 1);

outp(PORT6,c+ 1);

outp(PORT7,c+ 1);

outp(PORT8,c+ 1);

break;

casePORT2 :

outp(PORT1,c+ 1);

(60)

File NET SUP.C May 18, 1988 11:05 AM

outp(PORT3,c+

outp(PORT4,c +

outp(PORT5,c+

outp(PORT6,c+

outp(PORT7,c+

outp(PORT8,c+

break;

casePORT3 :

outp(PORT1,c+ 1);

outp(PORT2,c+ 1);

outp(PORT3,c);

outp(PORT4,c+ 1);

outp(PORT5,c+ 1);

outp(PORT6,c+ 1);

outp(PORT7,c+ 1);

outp(PORT8,c+ 1);

break;

casePORT4 :

outp(PORT1,c + 1);

outp(PORT2,c+ 1);

outp(PORT3,c + 1);

outp(PORT4,c);

outp(PORT5,c + 1);

outp(PORT6,c + 1);

outp(PORT7,c+ 1);

outp(PORT8,c+ 1);

break;

casePORT5:

outp(PORT1,c + 1);

outp(PORT2,c+ 1);

outp(PORT3,c+ 1);

outp(PORT4,c+ 1);

outp(PORT5,c);

(61)

File NET SUP.C May 18, 1988 11:05 AM

outp(PORT7,c+1);

outp(PORT8,c+ 1);

break;

case PORT6:

outp(PORT1,c + 1);

outp(PORT2,c+ 1);

outp(PORT3,c+ 1);

outp(PORT4,c+ 1);

outp(PORT5,c + 1);

outp(PORT6,c);

outp(PORT7,c + 1);

outp(PORT8,c + 1);

break;

casePORT7:

outp(PORT1,c + 1);

outp(PORT2,c+ 1);

outp(PORT3,c+ 1);

outp(PORT4,c+ 1);

outp(PORT5,c + 1);

outp(PORT6,c+1);

outp(PORT7,c);

outp(PORT8,c+ 1);

break;

casePORT8:

outp(PORT1,c+ 1);

outp(PORT2,c + 1);

outp(PORT3,c+ 1);

outp(PORT4,c+ 1);

outp(PORT5,c+ 1);

outp(PORT6,c+ 1);

outp(PORT7,c+ 1);

outp(PORT8,c);

break;

(62)

FileNET_SUP.C May 18, 1988 11:05AM

6.4.3 Shut down

Theshut down function causesthe RTS linesof each portto become

inactive in asequenceasdetermined bythenetworktopology. Thisfunction

iscalled whenthe firstcharacter of a packetisdetected.

/***************************************************************

Thisfunction causestheports tobeshut off atthe varioustimedelaysas

determinedbythetopologyofthenetwork.

***************************************************************/

shut down(port)

unsigned charport;

intrtsval,portnum,i,j;

rtsval=0;

switch (port)

{

case 1:

portnum =0;

break;

case2:

portnum = 1;

break;

case4:

portnum=2;

break;

case8:

(63)

File NET_SUP.C May 18, 1988 11:05 AM

break;

case 16:

portnum =4;

break;

case32:

portnum =5;

break;

case64:

portnum =6;

break;

case 128:

portnum =7;

break;

default:

outp(RTS_PORT,255);

retum(-1);

}

j=0;

for(i=1;i< =500;i+ +)

{

if(j < 8 &&sdmat[portnum][j][0] < = i) {

rtsval = rtsvallsdmat[portnum][j][1];

outp(RTS_PORT,rtsval);

j+ +;

} }

=port;

(64)

File NET SUP.C May 18, 1988 1 1:05AM

return(portnum + 1);

}

6.4.4 Rsam

Thefunction Rsamcauses a 1 Milli Second delay. Thiscausesthe

programtosamplethe portsonceevery milli second and alsotocountfor

errorinsertion aswell astime out.

/***************************************************************

This functioncausesthe 1 mSec. time tobeinvoked.

***************************************************************,

rsam()

{

inti=0;

intj.k;

chare;

while(1)

{

if(psam(TIM_READ,32))

{

stime + +;

while(1)

{

if(I (psam(TIM_READ,32)))

break;

}

break;

(65)

File NET_SUP.C

May 18, 1988 1 1:05AM

6.4.5Psam

Thefunction Psam isused to testa bitofa port, it ispassedthe port

address and the valueofthe bitto betested. Itreturns a zero ifthe bitis not

set andthe valueofthe bit if itis.

j***************************************************************

This function returns a boolean representing weather a bit of the

requestedportisset or not.

**********************************************************,,.,,.,,.,,.,,.

psam(port,andval)

intport.andval;

{

charcr;

cr=inp(port);

return(cr&andval);

}

6.5.6Packet_check

The Packet checkfunctionevaluatesthe bytesin the packet and prints

the resultsto both thescreen andthedata logfile. It checksthe packetfor

(66)

HleNET_SUP.C May 18, 198811:05AM

Thisfunction checksthepacketfor headerandsizeaccuracy.

********************************,(.**,t.*,(.,t.,j.,(.,i.*,(.,t.,(.***:(.*,i.,t.**********/

packet_check()

{

interror=0;

if(collision)

return(O);

printf("CHECKINGTHE PACKET\n");

if(packet[0]!= 0x55 Hpacket[1]! = 0x55 )

{

printf("

improper pre-ambleVi");

fprintfffpw,"improper pre-amble\n");

error= 1;

}

if(packet[2] I= pn)

{

printf("

packet portnumber(%d) doesnotmatch theport received

from(%d)\n",packet[2],pn);

fprintf(fpw,"packetportnumber(%d)doesnotmatch theport

receivedfrom(%d)\n",packet[2],pn);

}

if(packet[2]< 0//packet[2] > 7)

{

printf("

packetis fromportINVALID ");

fprintf(fpw,"packet is fromportINVALID ");

}

else

{

(67)

File NET_SUP.C May 18, 1988 11:05 AM

fprintf(fpw,"packetisfromport%d ",packet[2J);

}

if(packet[3] < 0\\packet[3]> 7)

{

printf("toportINVALID ");

fprintfffpw,"toportINVALID ");

}

else

{

printf("toport %d",packet[3]);

fprintf(fpw,"toport

%d"

,packet[3]);

}

if((packet[4]+10) = = ccount)

{

printff", isofsize %d andisoftype ",packet[4]+ 10);

fprintfffpw,"

isofsize %d andisoftype ",packet[4]+ 10);

}

else

{

printf("\npacketsize field doesnot match number ofcharacters

sen1\nsizefield = %d, number ofdata bytes = %d\npackettypeis

",packet[4],ccount-10);

fprintf(fpw,"npacketsize field doesnot match number ofcharacters

sent\nsizefield = %d, number ofdata bytes = %d\npackettypeis

",packet[4],ccount-10);

}

switch (packet[5])

{

case 1 :

printf("data\n");

fprintf(fpw,"data\n");

break;

case2 :

(68)

FileNET_SUP.C

May 18, 1988 11:05AM

fprintfffpw,"ack\n");

break;

case3:

printf("nack\n");

fprintf(fpw,"nack\n"); break;

default:

printf("unknown\n");

fprintfffpw, "unknown\n");

break;

(69)

FileMENU.C May 18, 1988 11:04AM

6.5 Menu.c

This file contains the function menu which causes the main menu of

options to be displayed to the console screen. It also receives the single

character responsefromthe keyboardand passesitasthe returned value.

Z*********************************************************,,.*****

FILE MENU.C

NetworkSimulator

Writtenby: ChrisMidgley

Datewritten: 10/6/87

Da telastrevision: 5111/88

This software is written as the controlling software for a project to

designalocalarea network simulator. Thissimulator wasdesignedaspartof

the requirements for the Master of Engineering Degree in the Computer

EngineeringDepartmentatthe RochesterInstitute ofTechnology.

This function causes the menu to be displayed on the screen. It reads

standard input(the keyboard) and returns the value which wasentered. All

inputvalidationisdoneattheupperlevel.

***************************************************************/

#indude"indude.h"

menu()

{

chare;

(70)

FileMENU.C May 18, 1988 11:04AM

printf("\n\n

printf("

printf("

printf("

printf("

printf("

return(getoneQ);

OPTIONS:\n\n");

(S)et-upthe SystemParameters\n\n"); (R)un theNetworkSimulation\n\n");

(P)rinttheCurrentDataFile\n\n");

(E)xittoDOS\n\n");

(?) Help ");

(71)

FileMISC.C May 18, 1988 11:03 AM

6.6Misc.c

The file misc.ccontainsthe functions center, getline, help, init, getone,

and check_end. These functions as the name of the file denotes are of a

miscellaneousnature.

6.6.1 Center

The function center causes the string passed as the argument to be

centered on an 80column screen.

FILE MISC.C

Network Simulator

Written by: ChrisMidgley

Date written: 10/6/87

Date lastrevision : 51 11/88

This software is written as the controlling software for a project to

design alocalarea network simulator. Thissimulator wasdesignedaspart of

the requirements for the Master of Engineering Degree in the Computer

EngineeringDepartmentattheRochesterInstituteofTechnology.

There are several functions in this file. They are described at their

declarationline.

***************************************************************/

#indude"indude.h"

(72)

File MISC.C May 18, 1988 1 1:03 AM

Thisfunction isusedto centerastring on the80 columnscreen.

center(s)

char*s;

{

inti,j;

j=strlen(s);

j=80-j;

jl=2;

for(i=0;i<j;i + +)

printf(" ");

printf("%s\n",s);

}

6.6.2 Getline

The function getline is passed the pointer to a string and returns the

numberof charactersthatit hasplaced into thatstring. It getsthe characters

fromthe keyboard and returns when a newline isencountered.

/***************************************************************

This functiongets a lineofinput fromthekeyboard.

***************************************************************/

getline(s)

char*s;

{

(73)

File MISC.C May 18, 1988 11:03 AM

charc;

while(1)

{

c=getchar();

s[i+ +]=c;

if(c= =\n')

{

s[i] =\0';

return(i);

}

6.6.3 Help

The function help is passed an integer parameter which it uses to

determine which of the help files it will display to the console screen. The

helpfilesaredisplayed usingthesystem call to the typecommand.

/***************************************************************

Thisfunction displaysthe varioushelpfilesassociated with theproject.

***************************************************************/

help(num)

intnum;

{

systemC'ds");

printf("\n\n\n\n");

switch(num)

{

case0:

(74)

File MISC.C May 18, 1988 11:03 AM

break;

case 1:

system("type netsiml.hlp ");

break;

case2:

system("type netsim2.hlp");

break;

case3:

systemf'type netsim3.hlp");

break;

case4:

system("type netsim4.hlp");

break;

case5:

system("type netsim5.hlp");

break;

case8:

system("type netsim8.hlp");

break;

case9:

system("type netsim9.hlp");

break;

case 10:

system("typenetsimW.hlp");

break;

case 1 1:

system("type netsim1l.hlp ");

break;

default :

break;

}

printf('\nPRESSRETURNTOCONTINUED)");

getline(option);

(75)

File MISC.C May 18, 1988 11:03 AM

return(num);

}

6.6.4 Init

The function init causes the network to be initialized. It calls the

functionssetmat and set sd to initializethe networktopology variables. It

also setstheerror rate and baud rate variablesto the initial values asdefined

inthedefines.hfile.

/***************************************************************

This program handles the initialization of many of the system parameters.

***************************************************************/

initQ

{

inti,dist[8];

for(i=0;i<8;i+ +)

distil]=1*500/7;

setmat(dist);

set_sd();

error =ERROR_RATE;

baud_rate=BAUD_RATE;

(76)

FileMISC.C May 18, 1988 11:03 AM

Thegetone function hastheeffectofwaiting forthe keyboard to be hit

and then returning the character which was struck. If the character is a

carriage return itreturnsthe newlinecharacter.

/***************************************************************

This function gets one character from the keyboard and echoes it back

to thescreen.

***************************************************************/

getoneQ

{

charc;

while (1)

{

if(kbhit())

{

if((c=getch()) = = 13)

printf('\n");

else

printf("%c",c);

return(c);

} } }

6.6.6Check_end

Thefunction check_end is called when evertheoption ofexit iscalled.

It is responsible for displaying a message on the console screen requesting

confirmation ofthe exit act. A user responseof 'Y'

or 'y'

(77)

File MISC.C May 18, 1988 11:03 AM

continue. Anyother response will return the usertowhere he was and allow

thesamepreviousoptions.

/***************************************************************

This function checks to make sure thatyou want to exit the system. It

returnsa 1 ifyou wanttoexit anda0ifyoudonot.

***************************************************************/

check end()

{

chare;

printf("Are you sure you wantto exit?(Y)esor(N)o");

if((c=getone()) = = 'y'Hc = = 'Y')

{

fdose(fpw);

return(1);

}

else

return(O);

(78)

FilePHEAD.C May 18, 1988 1 1:03 AM

6.7 Phead.c

The file phead.c contains the function printhead which displays the

heading messageforthe main menu ofthefixture.

Z**********************************************,!.****************

FILEPHEAD.C

Network Simulator

Written by: ChrisMidgley

Datewritten: 10/6/87

Date lastrevision : 51 11/88

This software is written as the controlling software for a project to

designalocalarea network simulator. Thissimulator wasdesignedaspartof

the requirements for the Master of Engineering Degree in the Computer

EngineeringDepartmentattheRochester InstituteofTechnology.

This functionprints outthe heading forthevariousdisplayscreens.

***************************************************************/

#indude"indude.h"

printheadf)

{

printf("\n\n\n");

center("

NetworkSimulator");

printf('\n");

center("Version 1.1");

printf('\n");

(79)

File PHEAD.C

May 18, 1988 11:03 AM

printf('\n");

(80)

File RNET.C

May 18, 1988 1 1:02 AM

6.8 Rnet.c

The file rnet.c contains two functions, run_net and e check. These

functionsare key, along with the functions

in net_sup.c, inthe operation of

the network.

6.8.1 Run_net

Thefunction run_net controlsthe operation ofthenetwork. It iscalled

from the main function and assumes control until the "M" key is struck to

return to the menu,orthe "E" keytoexit NETSIM.

/***************************************************************

FILERNET.C

Network Simulator

Written by: ChrisMidgley

Datewritten: 10/6/87

Datelastrevision: 5111/88

This software is written as the controlling software for a project to

design

a localareanetworksimulator. Thissimulator wasdesignedas partofthe

requirements for the Master of Engineering Degree in the Computer

Engineering

Departmentatthe Rochester InstituteofTechnology.

***************************************************************!

(81)

File RNET.C May 18, 1988 11:02 AM

#define TIME_OUT1000

I*

etimeisa counterwhich provides therandomnumberforerrorgeneration

stimeisthetimeouttimerincrementedbythemotherboardclock

time outisthevariable usedfortheactualtimeoutitis firstsetto thedefaultvalue andthen modifiedbythebaudrate.

make errorisa flag which issetifthepacket shouldhavea networkinduced

error.

cur_portmaintainsthecurrentactive port andisusedindetecting collisions.

Ipc isaflag used toonlyprintthelongpacket message

collision is theflag which issetifa collision

longerr isa flag which issetifalongpacket

ccountisa character counterforthepacket.

pacsizeissetfrom thepacketsize fieldand usedto comparethepacket lengthand actuallength.

packetisacharacterstringwhich holdsthepacket

longintetime,stime;

longinttime out;

inti,make_error,pn,cur_port,lpc,collision,longerr,ccount,pacsize;

(82)

File RNET.C May 18, 1988 1 1:02 AM

/*

This function isthe network operation function. Itis calledfrom the main

program. It oversees the operation of the expansion board and logs the

information transmittedoverthenet.*/

run net()

unsignedcharc;

intcol;

time_out=TIME_OUT;

longerr=0;

etime =inp(TIM_READ);

I*

modifythetimeoutvalue basedon thebaudrate. */

switch (baud val)

{

case B 1200:

time out*

=8;

break;

caseB2400:

time out*

=4;

break;

case B4800 :

time out*

=2;

break;

default:

break;

I*

resetports */

(83)

File RNET.C May 18, 1988 1 1:02 AM

/*

Loop looking for the first character of the packet. Process a packet

whendetected. */

while(1)

{

lpc=1;

ccount=0;

collision =0;

if(kbhit())

if((c=getch()) = = 'm'//c = = 'M')

{

systemC'ds");

return(1);

}

else

if(c==,q'Hc=='Q'llc=='e'llc==,E')

{

systemC'ds");

return(-1);

}

stime = 0;

outp(RTS_PORT,0);

if(c = inp(AVAIL_PORT))

References

Related documents

An analysis of the economic contribution of the software industry examined the effect of software activity on the Lebanese economy by measuring it in terms of output and value

This essay asserts that to effectively degrade and ultimately destroy the Islamic State of Iraq and Syria (ISIS), and to topple the Bashar al-Assad’s regime, the international

At the end of '99, the standards for reservist training statewide jumped to 650 hours but Blanas could have grandfathered Jack Sellers and other major cronies the way Sheriff

The projected gains over the years 2000 to 2040 in life and active life expectancies, and expected years of dependency at age 65for males and females, for alternatives I, II, and

For helpful overviews of the global situation, see Steven Hahn, &#34;Class and State in Postemancipation Societies: Southern Planters in Comparative Perspective,&#34;

Xu Jie, Cong Lei and Li Yan, “ Fabrication and mechanical properties of short sisal fibre reinforced composites used for dental application ,” 18 th International Conference

It is proved the existence of multivalent solutions for the Riemann–Hilbert problem in the general settings of finitely connected domains bounded by mutually disjoint Jordan

As a teacher, implement- ing preventative interventions and techniques may help students manage their anxiety or learn positive skills to prevent anxiety.. where and