-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheth.cpp
147 lines (124 loc) · 4.04 KB
/
eth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************
*
* DESCRIPTION: Atomic Model Ethernet
*
* AUTHOR: Ariel Gonzalez
*
* EMAIL: mailto://egonzalz@dc.uba.ar
* mailto://agonzalez@tecnet-ibermatica.com.ar
*
* DATE: 26/9/2003
*
*******************************************************************/
/** include files **/
#include "eth.h" // class Ethernet
#include "message.h" // class ExternalMessage, InternalMessage
#include "mainsimu.h" // MainSimulator::Instance().getParameter( ... )
#include "strutil.h" // str2Int
/** public functions **/
/*******************************************************************
* Function Name: Ethernet
* Description:
********************************************************************/
Ethernet::Ethernet( const string &name )
: Atomic( name )
, in1( addInputPort( "in1" ) )
, in2( addInputPort( "in2" ) )
, in3( addInputPort( "in3" ) )
, inhabilitar( addInputPort( "inhabilitar" ) )
, habilitar( addInputPort( "habilitar" ) )
, out1( addOutputPort( "out1" ) )
, out2( addOutputPort( "out2" ) )
, out3( addOutputPort( "out3" ) )
, delay( 0, 0, 0, 10 )
{
string time( MainSimulator::Instance().getParameter( description(), "delay" ) ) ;
if( time != "" )
delay = time ;
}
/*******************************************************************
* Function Name: initFunction
* Description:
* Precondition: El tiempo del proximo evento interno es Infinito
********************************************************************/
Model &Ethernet::initFunction()
{
string nf1( MainSimulator::Instance().getParameter( description(), "nodo_1" ) ) ;
string nf2( MainSimulator::Instance().getParameter( description(), "nodo_2" ) ) ;
string nf3( MainSimulator::Instance().getParameter( description(), "nodo_3" ) ) ;
nodo_1 = str2Int( nf1 );
nodo_2 = str2Int( nf2 );
nodo_3 = str2Int( nf3 );
hab1 = 1;
hab2 = 1;
hab3 = 1;
hay_pedido = 0;
return *this ;
}
/*******************************************************************
* Function Name: externalFunction
* Description:
********************************************************************/
Model &Ethernet::externalFunction( const ExternalMessage &msg )
{
// si el evento llega por un puerto IN que no esta
// habilitado, no hago nada...
if ( ( state() == passive ) &&
(( msg.port() == in1 ) && ( hab1 == 1 )) ||
(( msg.port() == in2 ) && ( hab2 == 1 )) ||
(( msg.port() == in3 ) && ( hab3 == 1 )))
{
pedido = msg.value();
hay_pedido = 1;
holdIn (active, delay);
}
if ( ( state() == passive ) &&
( msg.port() == inhabilitar ) )
{
cout << msg.time() << " / ETH / Deshabilitando Boca #" << msg.value() << "\n";
if ( msg.value() == 1 ) hab1 = 0;
if ( msg.value() == 2 ) hab2 = 0;
if ( msg.value() == 3 ) hab3 = 0;
hay_pedido = 0;
holdIn (active, delay);
}
if ( ( state() == passive ) &&
( msg.port() == habilitar ) )
{
cout << msg.time() << " / ETH / Habilitando Boca #" << msg.value() << "\n";
if ( msg.value() == 1 ) hab1 = 1;
if ( msg.value() == 2 ) hab2 = 1;
if ( msg.value() == 3 ) hab3 = 1;
hay_pedido = 0;
holdIn (active, delay);
}
return *this;
}
/*******************************************************************
* Function Name: internalFunction
* Description:
********************************************************************/
Model &Ethernet::internalFunction( const InternalMessage &msg )
{
hay_pedido = 0;
passivate();
return *this ;
}
/*******************************************************************
* Function Name: outputFunction
* Description:
********************************************************************/
Model &Ethernet::outputFunction( const InternalMessage &msg )
{
if (hay_pedido == 1)
{
int destino = obtener_destino_mensaje_red (pedido);
if (( destino == nodo_1 ) && ( hab1 == 1 ))
sendOutput( msg.time(), out1, pedido ) ;
if (( destino == nodo_2 ) && ( hab2 == 1 ))
sendOutput( msg.time(), out2, pedido ) ;
if (( destino == nodo_3 ) && ( hab3 == 1 ))
sendOutput( msg.time(), out3, pedido ) ;
}
return *this ;
}