• Nenhum resultado encontrado

Trabalhos Futuros

No documento Cap´ıtulo 1 Introdu¸ c˜ ao (páginas 118-154)

propˆos e avaliou uma t´ecnica de c´alculo do intervalo de controle do temporizador.

Com base em t´ecnicas bem conhecidas e testadas, importantes conclus˜oes e ade-qua¸c˜oes foram sugeridas para as RSSF.

Referˆ encias Bibliogr´ aficas

[1] DELICATO, F. C., Middleware Baseado em Servi¸cos para Redes de Sensores Sem Fio, Tese de Doutorado, GTA, COPPE, Universidade Federal do Rio de Janeiro, Rio de Janeiro, RJ, Brasil, Junho 2005.

[2] TILAK, S., ABU-GHAZALEH, N. B., HEINZELMAN, W., “A taxonomy of wireless micro-sensor network models”, ACM SIGMOBILE Mobile Com-puting and Communications Review, v. 6, n. 2, pp. 28–36, Abril 2002.

[3] DE OLIVEIRA CUNHA, D., Rede sem Fio De M´ultiplos Saltos: Protocolos Espec´ıficos para Aplica¸c˜oes e Roteamento com Suporte `a Diversidade Co-operativa, Tese de Doutorado, GTA, COPPE, Universidade Federal do Rio de Janeiro, Rio de Janeiro, RJ, Brasil, Julho 2008.

[4] CORSON, S., MACKER, J., “Mobile Ad hoc Networking (MANET): Routing Protocol Performance Issues and Evaluation Considerations”,Request for Comments: 2501, Janeiro 1999.

[5] HEINZELMAN, W., CHANDRAKASAN, A., BALAKRISHNAN, H., “Energy-Efficient Communication Protocol for Wireless Microsensor Networks”.

In: In Proccedings of the Hawaii Conference on System Sciences, p. 8020, Janeiro 2000.

[6] XU, Y., HEIDEMANN, J., ESTRIN, D., Adaptive Energy-Conserving Routing for Multihop Ad Hoc Networks, Relat´orio T´ecnico 527, USC/Information Sciences Institute, Outubro 2000.

[7] HAVINGA, P. J. M., SMIT, G. J. M., BOS, M., “Energy-efficient Adaptive Wireless Network Design”. In: The Fifth Symposium on Computers and Communications (ISCC’00), p. 502, Antibes, France, Julho 2000.

[8] FEENEY, L. M., NILSSON, M., “Investigating the Energy Consumption of a Wireless Network Interface in an Ad Hoc Networking Environment”. In:

IEEE INFOCOM, v. 3, pp. 1548–1557, Anchorage, AK, USA, Mar¸co 2001.

[9] SHNAYDER, V., HEMPSTEAD, M., RONG CHEN, B., et al., “Simulating the power consumption of large-scale sensor network applications”. In:

Proceedings of the First ACM Conference on Embedded Networked Sensor Systems, SenSys, pp. 188–200, ACM Press, 2004.

[10] FOK, C.-L., ROMAN, G.-C., LU, C., “Rapid Development and Flexible De-ployment of Adaptive Wireless Sensor Network Applications”, 25th IEEE International Conference on Distributed Computing Systems (ICDCS’05), pp. 653–662, 2005.

[11] VIEIRA, M. A. M.,BEAN: Uma Plataforma Computacional para Rede de Sen-sores Sem Fio, Disserta¸c˜ao de mestrado, Universidade Federal de Minas Gerais, Belo Horizonte, MG, Brasil, Abril 2004.

[12] YIH WAN, C., EISENMAN, S. B., “CODA: Congestion detection and avoi-dance in sensor networks”. In: Proceedings of the First ACM Conference on Embedded Networked Sensor Systems, SenSys, pp. 266–279, ACM Press, Novembro 2003.

[13] FLOYD, S., JACOBSON, V., “Random Early Detection Gateways for Conges-tion Avoidance”. In: IEEE/ACM Transactions on Networking, v. 1, pp.

397–413, Agosto 1993.

[14] SANKARASUBRAMANIAM, Y., AKAN, O., AKYILDIZ, I., “ESRT: Event-to-Sink Reliable Transport in Wireless Sensor Networks”. In: In Proce-edings of MobiHoc 03, ACM, pp. 177–188, Annapolis, Maryland, USA, Junho 2003.

[15] PEREIRA, M. R., DE AMORIM, C. L., DE CASTRO, M. C. S., “Tutorial sobre Redes de Sensores”. In: Cadernos do IME, v. 14, p. 15, Instituto de Matem´atica e Estat´ıstica (IME) - UERJ, 2003.

[16] STANN, F., HEIDEMANN, J., “RMST: Reliable Data Transport in Sensor Networks”. In: Proceedings of the First International Workshop on Sensor Net Protocols and Applications, pp. 102–112, Anchorage, Alaska, USA, 2003.

[17] INTANAGONWIWAT, C., GOVINDAN, R., ESTRIN, D., “Directed diffusion:

a scalable and robust communication paradigm for sensor networks”. In:

MobiCom ’00: Proceedings of the 6th annual international conference on Mobile computing and networking, pp. 56–67, ACM Press: New York, NY, USA, 2000.

[18] GIANCOLI, E., JABOUR, F., PEDROZA, A., “Collaborative Transport Con-trol Protocol”. In: Proceedings of IEEE International Conference on Computer and Electrical Engineering, pp. 373–377, Phuket, Tailˆandia, Dezembro 2008.

[19] GIANCOLI, E., JABOUR, F., PEDROZA, A., “Protocolo de Transporte Co-laborativo para Redes de Sensores sem Fio”. In: IX Workshop de Testes e Tolerˆancia a Falhas do Simp´osio Brasileiro de Redes de Computadores - SBRC´2008, p. 12, Rio de Janeiro, Brasil, Dezembro 2008.

[20] COMER, D. E., Interliga¸c˜ao em Rede com TCP/IP. 3rd ed., v. 1. Editora Campus, 1998.

[21] “Java”, http://java.sun.com, acesso em abril de 2006.

[22] LEVIS, P., MADDEN, S., POLASTRE, J., et al., “TinyOS: An operating sys-tem for wireless sensor networks”. In: Ambient Intelligence, pp. 115–148, Springer-Verlag: New York, NY, USA, 2004.

[23] “TinyOS”, http://www.tinyos.net/, acesso em fevereiro de 2009.

[24] LEVIS, P., LEE, N., WELSH, M., et al., “”TOSSIM”: Accurate and Scalable Simulation of Entire ”TinyOS”Applications”, Novembro 2003.

[25] CHEVALLAY, C., VAN, R. E., HALL, D. T. A., “Self-organization Protocols for Wireless Sensor Networks”. In: In Thirty Sixth Conference on Infor-mation Sciences and Systems, 2002.

[26] ROEMER, K., MATTERN, F., “The Design Space of Wireless Sensor Networks”, IEEE Wireless Communications, v. 11, n. 6, pp. 54–61, De-zembro 2004.

[27] SHAH, R. C., ROY, S., JAIN, S., et al., “Data MULEs: Modeling and Analy-sis of a Three-tier Architecture for Sparse Sensor Networks”, Ad Hoc Networks, v. 1, n. 2-3, pp. 215–233, Setembro 2003.

[28] LOUREIRO, A. A. F., NOGUEIRA, J. M. S., RUIZ, L. B., et al., “Redes de Sensores Sem Fio”, XXI SBRC, pp. 179–226, 2003, Brasil.

[29] RUIZ, L. B., CORREIA, L. H. A., VIEIRA, L. F. M., et al., “Arquiteturas para Redes de Sensores Sem Fio”,XXII SBRC, Maio 2004, Brasil.

[30] HAENSELMANN, T., “Wireless Sensor Network textbook”, http://www.informatik.uni-mannheim.de/˜haensel/sn book, acesso em abril 2006.

[31] CHIANG, M. W., ZILIC, Z., CHENARD, J.-S., et al., “Architectures of Incre-ased Availability Wireless Sensor Network Nodes”. In: ITC ’04: Procee-dings of the International Test Conference on International Test Confe-rence, pp. 1232–1241, IEEE Computer Society: Washington, DC, USA, 2004.

[32] TILAK, S., ABU-GHAZALEH, N. B., HEINZELMAN, W., “Infrastructure tradeoffs for sensor networks”. In: WSNA ’02: Proceedings of the 1st ACM international workshop on Wireless sensor networks and applications, pp.

49–58, ACM Press: New York, NY, USA, 2002.

[33] PINTO, A., Mecanismo de Agrega¸c˜ao de Dados Baseado em T´ecnicas Pa-ram´etricas Aplicado em Redes de Sensores, Disserta¸c˜ao de Mestrado, COPPE/UFRJ, Rio de Janeiro, RJ, Brasil, 2004.

[34] JABOUR, F., GIANCOLI, E., PEDROZA, A., “Redes de sensores m´oveis:

an´alise da velocidade, comunica¸c˜ao e esfor¸co computacional”. In: 7th In-ternational Information and Telecommunication Technologies Symposium - I2TS, p. 8, Foz do Igua¸cu, Brasil, Dezembro 2008.

[35] JABOUR, F., GIANCOLI, E., PEDROZA, A., “Mobility support for wireless sensor networks”. In: Proceedings of IEEE International Conference on Computer and Electrical Engineering, pp. 630–634, Phuket, Tailˆandia, Dezembro 2008.

[36] JABOUR, F., GIANCOLI, E., PEDROZA, A., “Mobility support for wireless sensor networks”. In: 3rd IEEE European Conference on Smart Sensing and Context (EuroSSC), p. 1, Outubro 2008.

[37] JABOUR, F., GIANCOLI, E., PEDROZA, A., “Um esquema em duas cama-das para suporte `a mobilidade em redes de sensores sem fio”. In: XXV Simp´osio Brasileiro de Telecomunica¸c˜oes, SBRT, p. 12, Recife, Brasil, Setembro 2007.

[38] ZIMMERMANN, H., “OSI Reference Model–The ISO Model of Architecture for Open Systems Interconnection”,Communications, IEEE Transactions on [legacy, pre - 1988], v. 28, n. 4, pp. 425–432, 1980.

[39] YE, W., HEIDEMANN, J., ESTRIN, D., “An Energy-Efficient MAC Protocol for Wireless Sensor Networks”. In: Proc. of International Annual Joint Conference of the IEEE Computer and Communications Societies, pp.

1567–1576, Junho 2002.

[40] WOO, A., “A transmission control scheme for media access in sensor networks”.

In: ACM/IEEE Mobicom Conference, pp. 221–235, 2001.

[41] BRAGINSKY, D., ESTRIN, D., “Rumor Routing Algorithm for Sensor Networks”. In: Proceedings of the First Workshop on Sensor Networks and Applications (WSNA), pp. 22–31, Atlanta, GA, Setembro 2002.

[42] KIM, Y. J., GOVINDAN, R., KARP, B., et al., “CLDP Robust Planarization for Geographic Face Routing”. In: Center for Embedded Network Sensing, p. 136, Janeiro 2005.

[43] IYER, R., KLEINROCK, L., “QoS Control For Sensor Networks”. In:

Proceedings of the IEEE International Conference on Communications (ICC´03), v. 26, pp. 517–521, Maio 2003.

[44] YU, Y., GOVINDAN, R., ESTRIN, D.,Geographical and energy aware routing:

A recursive data dissemination protocol for wireless sensor networks, Re-lat´orio t´ecnico, UCLA Computer Science Dept., Maio 2001.

[45] AGUAYO, D., BICKET, J., MORRIS, R.,SrcRR: A High Throughput Routing Protocol for 802.11 Mesh Networks (DRAFT), Relat´orio t´ecnico, MIT, 2005.

[46] AKYILDIZ, I. F., SU, W., SANKARASUBRAMANIAM, Y., et al., “Wireless Sensor Networks: A Survey”, Computer Networks, v. 38, pp. 393–422, 2002.

[47] WANG, C., SOHRABY, K., LI, B., et al., “Issues of transport control protocols for wireless sensor networks”. In: Proceedings of International Conference on Communications, Circuits and Systems, v. 1, pp. 422–426, Arkansas Univ., Fayetteville, AR, USA, Maio 2005.

[48] ALLMAN, M., PAXSON, V., STEVENS, W., “TCP Congestion Control”, RFC 2581 (Proposed Standard), Abril 1999, atualizada pela RFC 3390.

[49] RAGHAVENDRA, C. S., KUMAR, V. K. P., HARIRI, S., “Reliability Analysis in Distributed Systems”,IEEE Trans. Comput., v. 37, n. 3, pp. 352–358, 1988.

[50] HEIMLICHER, S., BAUMANN, R., MAY, M., et al., “SaFT: Reliable Trans-port in Mobile Networks”. In: IEEE International Conference on Mobile Adhoc and Sensor Systems (MASS), pp. 477–480, IEEE MASS 2006: Van-couver B.C., Canada, Outubro 2006.

[51] IYER, Y. G., GANDHAM, S., VENKATESAN, S., “STCP: A Generic Trans-port Layer Protocol for Wireless Sensor Networks”. In: Proceedings of 14th International Conference on Computer Communications and Networks, pp. 449–454, Houston, TX, USA, 2005.

[52] POSTEL, J., “User Datagram Protocol”, RFC 768 (Standard), Agosto 1980.

[53] TANENBAUM, A. S., Redes de Computadores. trad. 4 ed. ed. Elsevier: Rio de Janeiro, 2003.

[54] BAKSHI, B. S., KRISHNA, P., VAIDYA, N. H., et al., “Improving Perfor-mance of TCP over Wireless Networks”. In: International Conference on Distributed Computing Systems, p. 1, 1997.

[55] WAN, C.-Y., CAMPBELL, A. T., KRISHNAMURTHY, L., “Pump-Slowly, Fetch-Quickly (PSFQ): A Reliable Transport Protocol for Sensor Networks”. In: IEEE Journal on Selected Areas in Communications, v. 23, n. 4, pp. 862–872, Atlanta, Georgia, USA, 2005.

[56] VASSIS, D., KORMENTZAS, G., ROUSKAS, A. N., et al., “The IEEE 802.11g standard fo high data rate WLANs”, IEEE Network, v. 19, n. 3, pp. 21–

26, 2005.

[57] COUTO, D. S. J.,High-Throughput Routing for Multi-Hop Wireless Network, Tese de Doutorado, Massachusetts Institute of Technology, 2004.

[58] CAMPISTA, M. E. M., Um Novo Protocolo de Roteamento para Redes em Malha sem Fio, Tese de Doutorado, GTA, COPPE, Universidade Federal do Rio de Janeiro, Rio de Janeiro, RJ, Brasil, Dezembro 2008.

[59] KUROSE, J. F., ROSS, K. W., Redes de Computadores e a Internet: Uma abordagem top-down. Trad. 3 ed. ed. Addison Wesley: S˜ao Paulo, Brasil, 2006.

[60] GIANCOLI, E., JABOUR, F., PEDROZA, A., “CTCP: Reliable Transport Control Protocol for Sensor Networks”. In: 2008 Fourth International Conference on Intelligent Sensors, Sensor Nertworks and Information Processing, p. 10, Sydney, Australia, Dezembro 2008.

[61] RISO, B. G., Engenharia de Protocolo com LOTOS/Iso. 1st ed. UFSC, 2004.

[62] NIELSEN, M., PLOTKIN, G., , et al., Petri Nets, Event Structures and Do-mains, Part I, Vol. 13. Theoretical Computer Science, 1981.

[63] MAZIERO, C. A., “ARP - Analisador de Rede Petri”, http://www.ppgia.pucpr.br/ maziero/diversos/petri/arp.html, 1990, acesso em dezembro de 2008.

[64] MILNER, R., “A Calculus of Communicating Systems”,Lecture Notes in Com-puter Science, v. 92, pp. 123–154, 1980.

[65] SMITH, H., FINGAR, P., “A page about the pi calculus (and Business Process Management)”, http://www.fairdene.com/picalculus/, acesso em junho de 2007.

[66] MILNER, R., PARROW, J., WALKER, D., “A calculus of mobile processes, parts”,I and II. Information and Computation, v. 100, pp. 1–77, 1992.

[67] MOLLER, F., STEVENS, P., “Edinburgh Concurrency Workbench User Ma-nual (Version 7.1)”, http://homepages.inf.ed.ac.uk/perdita/cwb/, acesso em dezembro de 2008.

[68] KAFURA, D., “The Concurrency WorkBench (CWB)”,

http://ei.cs.vt.edu/ cs5204/fall99/ccs.html, acesso em junho de 2007.

[69] SPIEGEL, M. R., Probabilidade e Estat´ıstica. Primeira ed. Cole¸c˜ao Schaum, Makron Books, 1978, Cap´ıtulo 1.

[70] SPIEGEL, M. R., Estat´ıstica. Terceira ed. Cole¸c˜ao Schaum, Makron Books, 1993, Cap´ıtulo 6.

[71] SEYMOUR LIPSCHUTZ, P., Probabilidade. Quarta ed. Cole¸c˜ao Schaum, Makron Books, 1993, Cap´ıtulos 3 e 4.

[72] “Java Platform, Standard Edition 6 API Specification”, http://java.sun.com/javase/6/docs/api/, acesso em janeiro de 2009.

[73] GANESAN, D., KRISHNAMACHARI, B., WOO, A., et al.,An empirical study of epidemic algorithms in large scale multihop wireless networks, Relat´orio t´ecnico, University of Massachusetts, Amherst, 2002.

[74] CROSSBOW, “Mica2 Series”, http://www.xbow.com, acesso em junho de 2008.

[75] SENTILLA, “moteiv: wireless sensor networks”,

http://www.sentilla.com/moteiv-transition.html, acesso em junho de 2008.

[76] ENGINEERING, C., LABORATORY, E. Z. N., “Btnodes - a distributed envi-ronment for prototyping ad hoc networks”, http://btnode.ethz.ch/, acesso em junho de 2008.

[77] OF ENGINEERING, D., SCIENCES, H. U. A., “Codeblue: Wireless sensor networks for medical care”, http://www.eecs.harvard.edu/ mdw/proj/co-deblue/, acesso em junho de 2008.

[78] GAY, D., WELSH, M., LEVIS, P., et al., “The nesC lan-guage: A holistic approach to networked embedded systems”, http://www.tinyos.net/papers/nesc.pdf, 2003.

[79] LEVIS, P., “Ad hoc routing component architecture”, http://www.tinyos.net/tinyos-1.x/doc/ad-hoc.pdf, acesso em fevereiro 2003.

[80] GBURZYNSKI, P., KAMINSKA, B., OLESINSKI, W., “A tiny and efficient wireless ad-hoc protocol for low-cost sensor networks”. In: DATE ’07:

Proceedings of the Conference on Design, Automation and Test in Europe, pp. 1557–1562, EDA Consortium: Nice, France, 2007.

[81] DEMORACSKI, L., “Fault-Tolerant Beacon Vector Routing for Mobile Ad Hoc Networks”. In: IPDPS ’05: Proceedings of the 19th IEEE International Parallel and Distributed Processing Symposium (IPDPS’05) - Workshop 16, p. 8, IEEE Computer Society: Washington, DC, USA, 2005.

[82] “Simulating TinyOS Networks”, http://www.cs.berkeley.edu/˜ pal/research/-tossim.html, acesso em junho de 2007.

[83] PRESSMAN, R., Engenharia de Software. McGraw-Hill Interamericana do Brasil, 2005.

[84] GIANCOLI, E., JABOUR, F., PEDROZA, A., “CTCP: Analisando a Entrega, Latˆencia e Consumo de Energia”. In: 7th International Information and Telecommunication Technologies Symposium - I2TS, p. 8, Foz do Igua¸cu, Brasil, Dezembro 2008.

[85] HEINZELMAN, W. R., CHANDRAKASAN, A., BALAKRISHNAN, H.,

“Energy-Efficient Communication Protocol for Wireless Microsensor Networks”. In: Proceedings of the 33rd Annual Hawaii International Con-ference, v. 2, p. 10, IEEE Computer Society: Washington, DC, USA, 2000.

[86] KIM, S., FONSECA, R., DUTTA, P., et al., “Flush: a reliable bulk transport protocol for multihop wireless networks”. In: SenSys ’07: Proceedings of the 5th international conference on Embedded networked sensor systems, pp. 351–365, ACM: Sydney, Australia, 2007.

[87] GIANCOLI, E., JABOUR, F., PEDROZA, A. C. P., “”CTCP: Analisando a Entrega, Latˆencia e Consumo de Energia””, Submiss˜ao como Special Issue

`

a IEEE Am´erica Latina, Fevereiro 2009, Artigo Premiado: Second Best Paper in I2TS 2008.

[88] GIANCOLI, E., JABOUR, F., PEDROZA, A. C. P., “Collaborative Transport Control Protocol for Wireless Sensor Networks”, Submetido a Telecom-munication Systems, Fevereiro 2009.

Apˆ endice A

C´ odigos do Simulador Estat´ıstico

Na tela chamadaJanela Principal, temos um menu de sele¸c˜ao que permite execu-tar a classe com as rotinas de c´alculo baseadas nas f´ormulas dos modelos estat´ısticos (ACK fim-a-fim ou conf. 1) (janela chamadaF´ormulas, `a direita na figura TAL) ou executar a classe que implementa oSimulador Estat´ıstico(ACK fim-a-fim, conf.

1 ou conf. 2) (janela na parte de baixo da referida figura). Esta ´ultima, inclusive, apresenta uma sa´ıda t´ıpica do simulador. Na figura A.1, podemos ver uma instˆancia de execu¸c˜ao do simulador utilizado no cap´ıtulo 4.

Anexo A.1: C´odigo Fonte do Simulador Estat´ıstico

/∗

S i m u l a d o r E s t a t i s t i c o . j a v a

∗/

package probCUmECDois ;

import j a v a . awt . e v e n t . KeyEvent ; import j a v a . i o . F i l e ;

import j a v a . i o . F i l e W r i t e r ; import j a v a . i o . I O E x c e p t i o n ; import j a v a . u t i l . Date ;

import j a v a x . s w i n g . J F i l e C h o o s e r ; import j a v a x . s w i n g . JO ptio nPan e ;

/∗ ∗

@ a u t h o r E u g e n i a J a b o u r

∗/

p u b l i c c l a s s S i m u l a d o r E s t a t i s t i c o extends j a v a x . s w i n g . JFrame {

S t r i n g v e r s a o = ” 1 . 0 . 1 ”, c a b e c a l h o L o g E m A r q u i v o , i f G e r a d o r D o L o o p D a C o n f D o i s ; byte h , R , i d , c o n f , a u x E n t r e g a s C o n f Z e r o , n um ero De Ex ec uco es ;

long r o d a d a s , e n t r e g a s , entregasComFalhasEmAcks , n a o E n t r e g a s , totalDeEntregasDeACKUm , t o t a l D e E n t r e g a s D e A C K D o i s , totalDeEntregasDeMSG , t o t a l D e F a l h a s D e N o s ;

f l o a t p , q , f ; No n o s [ ] ;

F i l e d i r e t o r i o C o r r e n t e = n u l l; F i l e W r i t e r e s c r e v e A r q u i v o = n u l l;

/∗ ∗ C r e a t e s new f o r m S i m u l a d o r E s t a t i s t i c o ∗/

p u b l i c S i m u l a d o r E s t a t i s t i c o ( ) {

Figura A.1: Execu¸c˜ao do Simulador

i n i t C o m p o n e n t s ( ) ;

t h i s. s e t L o c a t i o n ( 6 0 , 1 0 0 ) ; t h i s. s e t S i z e ( 9 0 0 , 3 5 6 ) ;

t h i s. s e t T i t l e (t h i s. g e t T i t l e ( ) + v e r s a o ) ; j R a d i o B u t t o n 1 . s e t S e l e c t e d (true) ;

j T e x t F i e l d 5 . g r a b F o c u s ( ) ;

j R a d i o B u t t o n 4 . s e t S e l e c t e d (true) ; }

p r i v a t e void i n i t C o m p o n e n t s ( ) {

//CRIA O FORMUL ´ARIO DE ENTRADA DE DADOS . O C ´ODIGO FOI SUPRIMIDO //ENCONTRE O C ´ODIGO COMPLETO EM h t t p : / / www . g t a . u f r j . b r /˜ e u g e n i a / }

p r i v a t e void j B u t t o n 2 A c t i o n P e r f o r m e d ( j a v a . awt . e v e n t . A c t i o n E v e n t e v t ) { t h i s. d i s p o s e ( ) ; }

p r i v a t e void j B u t t o n 1 A c t i o n P e r f o r m e d ( j a v a . awt . e v e n t . A c t i o n E v e n t e v t ) { r o d a ( ) ; }

//UMA S ´ERIE DE TRATAMENTOS DE EVENTOS DE NAVEGAC¸ ˜AO PELO FORMUL ´ARIO //FORAM SUPRIMIDOS . ENCONTRE O C ´ODIGO COMPLETO EM

// h t t p : / / www . g t a . u f r j . b r /˜ e u g e n i a /

p r i v a t e void r o d a ( ) { i f ( ! v a l i d a F o r m ( ) ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g (t h i s, ”Erro no f o r m u l´a r i o ! ”) ; return; }

f o r (i n t numExec = 1 ; numExec<= nu me roD eE xe cuc oe s ; numExec++) { e n t r e g a s = 0 ;

entregasComFalhasEmAcks = 0 ; n a o E n t r e g a s = 0 ;

totalDeEntregasDeACKUm = 0 ; t o t a l D e E n t r e g a s D e A C K D o i s = 0 ; totalDeEntregasDeMSG = 0 ; t o t a l D e F a l h a s D e N o s = 0 ;

long umPorCento = r o d a d a s / 1 0 0 , andamento = 1 ;

System . o u t . p r i n t (”\n”+ numExec + ” ) ”) ; f o r (i n t i = 0 ; i < r o d a d a s ; i ++) {

i f ( j R a d i o B u t t o n 5 . i s S e l e c t e d ( ) ) {

i n i c i a l i z a A r q u i v o D e S a i d a ( numExec +” . ” + i ) ; } i f ( i > ( andamento umPorCento ) ) {

i f ( andamento % 10 == 0 ) { System . o u t . p r i n t (”\n”) ; }

System . o u t . p r i n t ( h +”/” + andamento + ”% ”) ;

andamento++; }

c r i a N o s ( ) ;

executaUmaRodada ( ) ; l i m p a N o s ( ) ;

i f ( j R a d i o B u t t o n 5 . i s S e l e c t e d ( ) ) { t ry {

e s c r e v e A r q u i v o . c l o s e ( ) ; } catch ( I O E x c e p t i o n e x ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g (t h i s, ”Erro de E/S”) ; e x . p r i n t S t a c k T r a c e ( ) ; } } }

i f ( j R a d i o B u t t o n 4 . i s S e l e c t e d ( ) ) { msg ( numExec + ” ) ”) ;

i m p r i m e R e l a t o r i o F i n a l R e s u m i d o ( ) ; } e l s e {

msg ( numExec + ” ) ”) ;

i m p r i m e R e l a t o r i o F i n a l ( ) ; } } System . o u t . p r i n t (”\nAcabou . . .\n”) ; }

p r i v a t e void c r i a N o s ( ) {

i f ( j R a d i o B u t t o n 1 . i s S e l e c t e d ( ) ) { c o n f = 1 ; }

i f ( j R a d i o B u t t o n 2 . i s S e l e c t e d ( ) ) { c o n f = 2 ; }

i f ( j R a d i o B u t t o n 3 . i s S e l e c t e d ( ) ) { c o n f = 0 ; }

f o r (byte i = 0 ; i <= h ; i ++) {

n o s [ i ] =new No ( i , c o n f , e s c r e v e A r q u i v o ) ; } n o s [ 0 ] . s e t M s g (true) ;}

p r i v a t e void l i m p a N o s ( ) { n o s = n u l l;

n o s =new No [ h + 1 ] ; }

p r i v a t e void z e r a F a l h a s ( ) { f o r (byte i = 0 ; i <= h ; i ++) {

n o s [ i ] . setEmFalha (f a l s e) ; } }

p r i v a t e void executaUmaRodada ( ) { i n t i ;

a u x E n t r e g a s C o n f Z e r o = 0 ; i f ( c o n f != 0 ) {

f o r ( i = 0 ; i < h ; i ++) { z e r a F a l h a s ( ) ;

i f ( c o n f == 1 ) {

i f ( ( ! n o s [ i ] . e x e c u t a P r o t o c o l o ( c o n f , R , p , q , f , n o s ) & ! n o s [ i + 1 ] . temMsg ( ) ) | ( n o s [ i + 1 ] . i s E m F a l h a ( ) ) ) {

e s c r e v e L i n h a ( ) ; break; } } e l s e { // c o n f 2

i f ( i == h 1 ) {

i f G e r a d o r D o L o o p D a C o n f D o i s =” 0|”+ i ;

n o s [ i ] . e x e c u t a P r o t o c o l o ( (byte) 1 , R , p , q , f , n o s ) ; e s c r e v e L i n h a ( ) ;

break; } e l s e {

i f ( ! n o s [ i ] . e x e c u t a P r o t o c o l o ( c o n f , R , p , q , f , n o s ) & ! n o s [ i + 1 ] . temMsg ( ) &

! n o s [ i + 2 ] . temMsg ( ) ) {

i f G e r a d o r D o L o o p D a C o n f D o i s =” 1|”+ i ;

e s c r e v e L i n h a ( ) ; break; }

i f ( n o s [ i + 1 ] . i s E m F a l h a ( ) & n o s [ i + 2 ] . i s E m F a l h a ( ) ) { i f G e r a d o r D o L o o p D a C o n f D o i s =” 2|”+ i ;

e s c r e v e L i n h a ( ) ; break; }

i f ( n o s [ i ] . i s A c k D o i s O k ( ) & n o s [ i + 1 ] . isAckUmOk ( ) ) { i ++;

i f ( i == h 1 ) {

i f G e r a d o r D o L o o p D a C o n f D o i s = ” 3|”+ i ;

n o s [ i ] . e x e c u t a P r o t o c o l o ( (byte) 1 , R , p , q , f , n o s ) ; e s c r e v e L i n h a ( ) ;

break; } e l s e {

i f G e r a d o r D o L o o p D a C o n f D o i s = ” 4|”+ i ; e s c r e v e L i n h a ( ) ;

continue; } } }

i f G e r a d o r D o L o o p D a C o n f D o i s =” 5|”+ i ; } e s c r e v e L i n h a ( ) ; }

} e l s e { // c o n f 0

f o r ( i = 0 ; i <= R ; i ++) { i n t j ;

z e r a F a l h a s ( ) ;

n o s [ h ] . s e t M s g (f a l s e) ; f o r ( j = 0 ; j < h ; j ++) {

i f ( ( (f l o a t) Math . random ( ) ) > f ) { t o t a l D e F a l h a s D e N o s ++;

e s c r e v e L i n h a ( ) ; break; }

i f ( ! n o s [ j ] . e n v i a (’M’, p , q , n o s ) ) { e s c r e v e L i n h a ( ) ;

break; } } i f ( j == h ) {

e s c r e v e L i n h a ( ) ; } i f ( n o s [ h ] . temMsg ( ) ) {

a u x E n t r e g a s C o n f Z e r o = 1 ; f o r ( j = h ; j > 0 ; j−−) {

i f ( ( (f l o a t) Math . random ( ) ) > f ) { t o t a l D e F a l h a s D e N o s ++;

e s c r e v e L i n h a ( ) ; break; }

i f ( ! n o s [ j ] . e n v i a (’A’, p , q , n o s ) ) { e s c r e v e L i n h a ( ) ;

break; } e l s e {

n o s [ j 1 ] . s e t M s g (f a l s e) ; e s c r e v e L i n h a ( ) ; } } i f ( j == 0 ) {

e s c r e v e L i n h a ( ) ; } } i f ( n o s [ 0 ] . isAckUmOk ( ) ) {

break; } } } f a z T o t a l i z a c o e s ( i ) ; }

p r i v a t e void f a z T o t a l i z a c o e s (i n t i ) { i f ( n o s [ h ] . temMsg ( ) ) {

i f ( c o n f == 1 ) { e n t r e g a s ++;

f o r (i n t j = 0 ; j < h ; j ++) { i f ( ! n o s [ j ] . isAckUmOk ( ) ) {

entregasComFalhasEmAcks++;

break; } } } i f ( c o n f == 2 ) {

e n t r e g a s ++;

f o r (i n t j = 0 ; j < ( h 1 ) ; j ++) { i f ( ! n o s [ j ] . i s A c k D o i s O k ( ) ) {

entregasComFalhasEmAcks++;

break; } } } i f ( c o n f == 0 ) {

e n t r e g a s += a u x E n t r e g a s C o n f Z e r o ; i f ( ! n o s [ 0 ] . isAckUmOk ( ) ) {

entregasComFalhasEmAcks++; } }

} e l s e {

n a o E n t r e g a s ++; }

f o r (i n t j = 0 ; j <= h ; j ++) { i f ( n o s [ j ] . isAckUmOk ( ) ) {

totalDeEntregasDeACKUm++; }

i f ( n o s [ j ] . i s A c k D o i s O k ( ) ) { t o t a l D e E n t r e g a s D e A C K D o i s ++; } i f ( n o s [ j ] . i s E m F a l h a ( ) ) {

t o t a l D e F a l h a s D e N o s ++; } } }

p r i v a t e void i m p r i m e R e l a t o r i o F i n a l R e s u m i d o ( ) {

f l o a t s u c e s s o s P e r c = 1 0 0 ( ( (f l o a t) e n t r e g a s (f l o a t) entregasComFalhasEmAcks ) / (f l o a t) r o d a d a s ) ; S t r i n g s t r i n g S u c e s s o s P e r c = F l o a t . t o S t r i n g ( s u c e s s o s P e r c ) ;

s t r i n g S u c e s s o s P e r c = s t r i n g S u c e s s o s P e r c . r e p l a c e (’ . ’, ’ , ’) ; f l o a t e n t r e g a s P e r c = 1 0 0 ( (f l o a t) e n t r e g a s / (f l o a t) r o d a d a s ) ; S t r i n g s t r i n g E n t r e g a s P e r c = F l o a t . t o S t r i n g ( e n t r e g a s P e r c ) ; s t r i n g E n t r e g a s P e r c = s t r i n g E n t r e g a s P e r c . r e p l a c e (’ . ’, ’ , ’) ; msg (”Rodadas=” + r o d a d a s + ” ; h=”+ h + ” ; conf : ” + c o n f +

” ; p=”+ p +” ; q=” + q +” ; f=” + f +” ;R=” + R ) ; msg (”\nSucessos : + s t r i n g S u c e s s o s P e r c + ” %;”) ; msg (”\tEntregas : + s t r i n g E n t r e g a s P e r c + ” %”) ; msg (”\t ( v . ” + v e r s a o +” ) ”) ;

msg (”\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n”) ; }

p r i v a t e void i m p r i m e R e l a t o r i o F i n a l ( ) {

f l o a t s u c e s s o s = ( ( (f l o a t) e n t r e g a s (f l o a t) entregasComFalhasEmAcks ) / (f l o a t) r o d a d a s ) ; f l o a t e n t r e g a s P e r c = 1 0 0 ( (f l o a t) e n t r e g a s / (f l o a t) r o d a d a s ) ;

f l o a t e n t r e g a s C o m F a l h a s E m A c k s P e r c = 1 0 0 ( (f l o a t) entregasComFalhasEmAcks / (f l o a t) r o d a d a s ) ; f l o a t n a o E n t r e g a s P e r c = 1 0 0 ( (f l o a t) n a o E n t r e g a s / (f l o a t) r o d a d a s ) ;

f l o a t totalDeEntregasDeACKUmPerc = 1 0 0 ( (f l o a t) totalDeEntregasDeACKUm / (f l o a t) ( r o d a d a s h ) ) ;

f l o a t t o t a l D e E n t r e g a s D e A C K D o i s P e r c = 1 0 0 ( (f l o a t) t o t a l D e E n t r e g a s D e A C K D o i s / (f l o a t) ( r o d a d a s ( h 1 ) ) ) ;

msg (new Date ( ) . t o S t r i n g ( ) + ” / Vers˜ao : + v e r s a o ) ;

msg (”\nRodadas = ” + r o d a d a s + ”\t S a l t o s : h = ” + h +” ( ” + ( h + 1 ) + ” n´os )\t c o n f : + c o n f +

”\np = ” + p +”\tq = ”+ q + ”\t f = ” + f +”\tRetransmiss˜oes : R = ” + R ) ; msg (”\n\nSucessos : + s u c e s s o s ) ;

msg (”\nEntregas ao sorvedouro : + e n t r e g a s + ” ( ”+ e n t r e g a s P e r c + ”%)”) ; msg (”\nEntregas com f a l h a s em ACKs: + entregasComFalhasEmAcks + ” ( ” +

e n t r e g a s C o m F a l h a s E m A c k s P e r c + ”%)”) ;

msg (”\nTotal n˜ao entregue : + n a o E n t r e g a s + ” ( ” + n a o E n t r e g a s P e r c +”%)”) ;

msg (”\nTotal de ACKs Uns entregues : + totalDeEntregasDeACKUm +

” ( ”+ totalDeEntregasDeACKUmPerc + ”%) ∗∗”) ;

msg (”\nTotal de ACKs Dois entregues : + t o t a l D e E n t r e g a s D e A C K D o i s +

” ( ”+ t o t a l D e E n t r e g a s D e A C K D o i s P e r c + ”%) ∗∗∗”) ;

msg (”\nTotal de f a l h a s de n´os : + t o t a l D e F a l h a s D e N o s + ∗∗∗∗”) ;

msg (”\n∗∗O ´ultimo n´o n˜ao recebe ACK Um. Resultado n˜ao validado para conf 0 . ”) ; msg (”\n∗∗∗ Os d o i s ´ultimos n´os n˜ao recebem ACK Dois”) ;

msg (”\n∗∗∗∗ o que f a l h o u continua e x i s t i n d o na pr´oxima rodada , supondo atua¸ao do roteamento”) ;

msg (”\n−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n”) ; }

p r i v a t e void msg ( S t r i n g m) { j T e x t A r e a 1 . append (m) ;

j T e x t A r e a 1 . s e t C a r e t P o s i t i o n ( j T e x t A r e a 1 . g e t T e x t ( ) . l e n g t h ( ) ) ; }

p r i v a t e boolean v a l i d a F o r m ( ) { t ry {

h = Byte . p a r s e B y t e ( j T e x t F i e l d 1 . g e t T e x t ( ) ) ; p = F l o a t . p a r s e F l o a t ( j T e x t F i e l d 2 . g e t T e x t ( ) ) ; p /= 1 0 0F ;

q = F l o a t . p a r s e F l o a t ( j T e x t F i e l d 3 . g e t T e x t ( ) ) ; q /= 1 0 0F ;

f = F l o a t . p a r s e F l o a t ( j T e x t F i e l d 6 . g e t T e x t ( ) ) ; f /= 1 0 0F ;

R = Byte . p a r s e B y t e ( j T e x t F i e l d 4 . g e t T e x t ( ) ) ;

nu me ro DeE xe cu coe s = Byte . p a r s e B y t e ( j T e x t F i e l d 7 . g e t T e x t ( ) ) ; r o d a d a s = Long . p a r s e L o n g ( j T e x t F i e l d 5 . g e t T e x t ( ) ) ;

} catch ( NumberFormatException n f e ) { j T e x t F i e l d 7 . g r a b F o c u s ( ) ;

return f a l s e; }

i f ( r o d a d a s < 1 | R< 0 | h < 1 | p< 0 | p > 1 0 0 | q < 0 | q> 1 0 0 | f < 0 | f > 1 0 0 | nu me ro DeE xe cu coe s < 1 | nu me ro DeE xe cu coe s > 1 0 ) {

return f a l s e; } e l s e {

n o s =newNo [ h + 1 ] ;

c a b e c a l h o L o g E m A r q u i v o = |”; f o r (i n t m = 0 ; m<= h ; m++) {

c a b e c a l h o L o g E m A r q u i v o += S t r i n g . v a l u e O f (m) + |; } } return true; }

p r i v a t e void i n i c i a l i z a A r q u i v o D e S a i d a ( S t r i n g argNumExecMaisRodada ) {

S t r i n g nomeArq = argNumExecMaisRodada + ” p” + p +” f ” + f + ” q ” + q +” r ” + R +” h” + h +

” v ”+ v e r s a o + ” . t x t ”;

J F i l e C h o o s e r j a n e l a D e f i n e N o m e D o A r q u i v o = new J F i l e C h o o s e r ( ) ;

j a n e l a D e f i n e N o m e D o A r q u i v o . s e t F i l e S e l e c t i o n M o d e ( J F i l e C h o o s e r . FILES ONLY ) ; j a n e l a D e f i n e N o m e D o A r q u i v o . s e t D i a l o g T i t l e (t h i s. g e t T i t l e ( ) + : Nome”) ; i f ( d i r e t o r i o C o r r e n t e != n u l l) {

j a n e l a D e f i n e N o m e D o A r q u i v o . s e t C u r r e n t D i r e c t o r y ( d i r e t o r i o C o r r e n t e ) ; } i f ( nomeArq != n u l l) {

j a n e l a D e f i n e N o m e D o A r q u i v o . s e t S e l e c t e d F i l e (new F i l e ( nomeArq ) ) ; } i n t r e s u l t = j a n e l a D e f i n e N o m e D o A r q u i v o . s h o w S a v e D i a l o g (t h i s) ;

i f ( j a n e l a D e f i n e N o m e D o A r q u i v o . g e t S e l e c t e d F i l e ( ) != n u l l && r e s u l t !=

J F i l e C h o o s e r . CANCEL OPTION) {

nomeArq = j a n e l a D e f i n e N o m e D o A r q u i v o . g e t S e l e c t e d F i l e ( ) . t o S t r i n g ( ) ; F i l e a r q u i v o =new F i l e ( nomeArq ) ;

d i r e t o r i o C o r r e n t e = j a n e l a D e f i n e N o m e D o A r q u i v o . g e t C u r r e n t D i r e c t o r y ( ) ; i f ( a r q u i v o . e x i s t s ( ) ) {

r e s u l t = JOpt ion Pane . s h o w O p t i o n D i a l o g (t h i s, ”Arquivo ”+

” j ˜ e x i s t e . Sobrescrever ?”, ”Cuidado ! ”,

JO ptio nPa ne . YES NO OPTION , JO ptio nPa ne . WARNING MESSAGE, n u l l, n u l l, n u l l) ; }

i f ( r e s u l t == JO ptio nPa ne . YES OPTION ) { a r q u i v o . d e l e t e ( ) ;

t ry {

e s c r e v e A r q u i v o = new F i l e W r i t e r ( a r q u i v o ) ;

e s c r e v e A r q u i v o . w r i t e ( c a b e c a l h o L o g E m A r q u i v o + ”\n”) ; } catch ( I O E x c e p t i o n e x ) {

JO ptio nPa ne . s h o w M e s s a g e D i a l o g (t h i s, ”Erro de E/S”) ; e x . p r i n t S t a c k T r a c e ( ) ; } } } }

p r i v a t e void e s c r e v e L i n h a ( ) {

i f ( ! j R a d i o B u t t o n 5 . i s S e l e c t e d ( ) ) { return; }

S t r i n g l i n h a ;

f o r (i n t k = 0 ; k<= h ; k++) { i f ( k == 0 ) {

l i n h a = |”; } e l s e {

l i n h a = ””; } i f ( n o s [ k ] . temMsg ( ) ) {

l i n h a += ”M”;

} e l s e {

l i n h a += ” ”; } i f ( n o s [ k ] . isAckUmOk ( ) ) {

l i n h a += ”1”;

} e l s e {

l i n h a += ” ”; }

i f ( n o s [ k ] . i s A c k D o i s O k ( ) ) {

l i n h a += ”2”;

} e l s e {

l i n h a += ” ”; } i f ( n o s [ k ] . i s E m F a l h a ( ) ) {

l i n h a += ” f|”; } e l s e {

l i n h a += |”; } t ry {

e s c r e v e A r q u i v o . w r i t e ( l i n h a ) ; } catch ( I O E x c e p t i o n e x ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g (t h i s, ”Erro de E/S”) ; e x . p r i n t S t a c k T r a c e ( ) ; } }

t ry {

e s c r e v e A r q u i v o . w r i t e ( i f G e r a d o r D o L o o p D a C o n f D o i s + ”\n”) ; } catch ( I O E x c e p t i o n e x ) {

JO ptio nPa ne . s h o w M e s s a g e D i a l o g (t h i s, ”Erro de E/S”) ; e x . p r i n t S t a c k T r a c e ( ) ; } }

p u b l i c s t a t i c void main ( S t r i n g a r g s [ ] ) {

j a v a . awt . EventQueue . i n v o k e L a t e r (new Runnable ( ) { p u b l i c void r u n ( ) {

new S i m u l a d o r E s t a t i s t i c o ( ) . s e t V i s i b l e (true) ; } }) ; } // V a r i a b l e s d e c l a r a t i o n do n o t m o d i f y //GENBEGIN : v a r i a b l e s p r i v a t e j a v a x . s w i n g . ButtonGroup b u t t o n G r o u p 1 ;

p r i v a t e j a v a x . s w i n g . J B u t t o n j B u t t o n 1 ; p r i v a t e j a v a x . s w i n g . J B u t t o n j B u t t o n 2 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 1 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 1 0 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 1 1 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 2 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 3 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 4 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 5 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 6 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 7 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 8 ; p r i v a t e j a v a x . s w i n g . J L a b e l j L a b e l 9 ;

p r i v a t e j a v a x . s w i n g . J R a d i o B u t t o n j R a d i o B u t t o n 1 ; p r i v a t e j a v a x . s w i n g . J R a d i o B u t t o n j R a d i o B u t t o n 2 ; p r i v a t e j a v a x . s w i n g . J R a d i o B u t t o n j R a d i o B u t t o n 3 ; p r i v a t e j a v a x . s w i n g . J R a d i o B u t t o n j R a d i o B u t t o n 4 ; p r i v a t e j a v a x . s w i n g . J R a d i o B u t t o n j R a d i o B u t t o n 5 ; p r i v a t e j a v a x . s w i n g . J S c r o l l P a n e j S c r o l l P a n e 1 ; p r i v a t e j a v a x . s w i n g . J T e x t A r e a j T e x t A r e a 1 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 1 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 2 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 3 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 4 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 5 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 6 ; p r i v a t e j a v a x . s w i n g . J T e x t F i e l d j T e x t F i e l d 7 ; // End o f v a r i a b l e s d e c l a r a t i o n //GENEND : v a r i a b l e s }

Anexo A.2: C´odigo Fonte da Classe N´o

package probCUmECDois ;

import j a v a . i o . F i l e W r i t e r ; import j a v a . i o . I O E x c e p t i o n ;

/∗ ∗

@ a u t h o r E u g e n i a J a b o u r

∗/

p u b l i c c l a s s No {

p r i v a t e byte i d , c o n f ;

p r i v a t e boolean msg , ackUmOk , ackDoisOk , emFalha ; F i l e W r i t e r fw ;

byte a c k E s p e r a d o = 1 ;

No (byte i d , byte c o n f , F i l e W r i t e r fw ) { t h i s. i d = i d ;

t h i s. c o n f = c o n f ; t h i s. setAckUmOk (f a l s e) ; t h i s. s e t M s g (f a l s e) ; t h i s. s e t A c k D o i s O k (f a l s e) ; t h i s. setEmFalha (f a l s e) ; t h i s. fw = fw ;

}

boolean e n v i a (char t i p o , f l o a t p , f l o a t q , No [ ] n o s ) { switch ( t i p o ) {

c a s e ’M’: // msg c o n f 1 , c o n f 2 e FaF i f ( (f l o a t) Math . random ( ) <= p ) {

n o s [ g e t I d ( ) + 1 ] . s e t M s g (true) ; i f ( a c k E s p e r a d o == 1 ) {

t h i s. setAckUmOk (f a l s e) ; } e l s e {

t h i s. s e t A c k D o i s O k (f a l s e) ; } e s c r e v e (”sM”) ;

return true; } e l s e {

e s c r e v e (”fM”) ; return f a l s e; }

c a s e ’A’: // a c k c o n f 1 e a c k 1 c o n f 2 e FaF i f ( (f l o a t) Math . random ( ) <= q ) {

e s c r e v e (”sA”) ;

n o s [ g e t I d ( ) 1 ] . setAckUmOk (true) ;

i f ( c o n f == 2 ) { // t h i s . g e t I d ( ) > 0 j ´a ´e t e s t a d o a b a i x o i f ( n o s [ g e t I d ( ) 1 ] . e n v i a (’B ’, p , q , n o s ) ) {

return true; } e l s e {

return f a l s e; } } return true;

} e l s e {

e s c r e v e (”fA”) ; return f a l s e; } c a s e ’B ’: // a c k 2 c o n f 2

i f ( g e t I d ( ) > 0 ) {

i f ( (f l o a t) Math . random ( ) <= q ) { n o s [ g e t I d ( ) 1 ] . s e t A c k D o i s O k (true) ; e s c r e v e (”sB”) ;

return true; } e l s e {

e s c r e v e (”fB”) ; return f a l s e; } } return true;

d e f a u l t:

return f a l s e; } }

boolean e x e c u t a P r o t o c o l o (byte c o n f , byte R , f l o a t p , f l o a t q , f l o a t f , No [ ] n o s ) { i f ( c o n f == 1 ) {

return e x e c u t a P r o t o c o l o C o n f U m (R , p , q , f , n o s ) ; } e l s e {

return e x e c u t a P r o t o c o l o C o n f D o i s (R , p , q , f , n o s ) ; } }

p r i v a t e boolean e x e c u t a P r o t o c o l o C o n f U m (byte R , f l o a t p , f l o a t q , f l o a t f , No [ ] n o s ) { f o r (i n t i = 0 ; i <= R ; i ++) {

e s c r e v e (”R1−” + i ) ;

i f ( e n v i a (’M’, p , q , n o s ) ) {

i f ( ( (f l o a t) Math . random ( ) ) <= f ) {

i f ( n o s [ g e t I d ( ) + 1 ] . e n v i a (’A’, p , q , n o s ) ) { return true; }

} e l s e {

n o s [ g e t I d ( ) + 1 ] . setEmFalha (true) ; e s c r e v e (”fN”) ;

return f a l s e; // f−>f a l h a no i n t e r v a l o c r ´ı t i c o . MSG p e r d i d a p / s e m p r e . ao c o n t i n u a no R . } } }

return f a l s e; }

p r i v a t e boolean e x e c u t a P r o t o c o l o C o n f D o i s (byte R , f l o a t p , f l o a t q , f l o a t f , No [ ] n o s ) { f o r (i n t i = 0 ; i <= R ; i ++) {

a c k E s p e r a d o = 2 ; e s c r e v e (”R2−” + i ) ;

i f ( e x e c u t a P r o t o c o l o C o n f U m ( (byte) 0 , p , q , f , n o s ) ) { a c k E s p e r a d o = 1 ;

i f ( n o s [ g e t I d ( ) + 1 ] . e x e c u t a P r o t o c o l o C o n f U m (R , p , q , f , n o s ) ) { return true; } } }

return f a l s e; }

p u b l i c boolean isAckUmOk ( ) { return ackUmOk ; }

p u b l i c void setAckUmOk (boolean ackUmOk ) { t h i s. ackUmOk = ackUmOk ;

i f ( c o n f == 1 ) {

t h i s. s e t M s g (f a l s e) ; } }

p u b l i c boolean temMsg ( ) { return msg ; }

p u b l i c void s e t M s g (boolean recebeuMSG ) { t h i s. msg = recebeuMSG ; }

p u b l i c boolean i s A c k D o i s O k ( ) { return ackDoisOk ; }

p u b l i c void s e t A c k D o i s O k (boolean ackDoisOk ) { t h i s. ackDoisOk = ackDoisOk ;

t h i s. s e t M s g (f a l s e) ; }

p u b l i c byte g e t I d ( ) { return i d ; }

p u b l i c byte g e t C o n f ( ) { return c o n f ; }

p u b l i c boolean i s E m F a l h a ( ) { return emFalha ; }

p u b l i c void setEmFalha (boolean emFalha ) { t h i s. emFalha = emFalha ; }

p r i v a t e void e s c r e v e ( S t r i n g s ) { i f ( fw == n u l l) {

return; }

i f ( s . s t a r t s W i t h (”fN”) ) {

s += ” [ ”+ (t h i s. g e t I d ( ) + 1 ) +” ] ; ”; } e l s e {

s += ” [ ”+ t h i s. g e t I d ( ) + ” ] ; ”; } t ry {

fw . w r i t e ( s ) ; fw . f l u s h ( ) ;

} catch ( I O E x c e p t i o n e x ) {

System . o u t . p r i n t l n (”Erro fw . w ri te (\”( ” + s + ” )\” ) ; ”) ; } } }

Anexo A.3: C´odigo Fonte da f´ormula probabil´ıstica

import j a v a . awt . e v e n t . KeyEvent ; import j a v a . i o . F i l e ;

import j a v a . i o . F i l e W r i t e r ; import j a v a . i o . I O E x c e p t i o n ; import j a v a . u t i l . Date ;

import j a v a x . s w i n g . J F i l e C h o o s e r ; import j a v a x . s w i n g . JOp tio nPan e ;

/∗ ∗

@ a u t h o r E u g e n i a J a b o u r

∗/

p u b l i c c l a s s PorFormula extends j a v a x . s w i n g . JFrame {

S t r i n g v e r s a o = ” 3 . 1 . 3 ”;

/∗ ∗ C r e a t e s new f o r m P o r F o r m u l a ∗/

p u b l i c PorFormula ( ) { i n i t C o m p o n e n t s ( ) ;

t h i s. s e t T i t l e (t h i s. g e t T i t l e ( ) + v e r s a o ) ; }

p r i v a t e void i n i t C o m p o n e n t s ( ) {

//CRIA O FORMUL ´ARIO DE ENTRADA DE DADOS . O C ´ODIGO FOI SUPRIMIDO //ENCONTRE O C ´ODIGO COMPLETO EM h t t p : / / www . g t a . u f r j . b r /˜ e u g e n i a / }

p r i v a t e void j M e n u I t e m 1 A c t i o n P e r f o r m e d ( j a v a . awt . e v e n t . A c t i o n E v e n t e v t ) { t h i s. d i s p o s e ( ) ;

}

p r i v a t e void geraPSporH ( F i l e W r i t e r e s c r e v e A r q u i v o ) {

double p , f , q , PS C1 , PS C1Nova , PS FaF C1 , PS FaF C1Nova , PS FaF 1ACK ; i n t r , h ;

t ry {

p = D o u b l e . p a r s e D o u b l e ( jTFp . g e t T e x t ( ) ) ; f = D o u b l e . p a r s e D o u b l e ( j T F f . g e t T e x t ( ) ) ; q = D o u b l e . p a r s e D o u b l e ( jTFq . g e t T e x t ( ) ) ; r = I n t e g e r . p a r s e I n t ( jTFr . g e t T e x t ( ) ) ; h = I n t e g e r . p a r s e I n t ( jTFh . g e t T e x t ( ) ) ; } catch ( NumberFormatException e x ) {

JO ptio nPa ne . s h o w M e s s a g e D i a l o g (t h i s, ”Erro nos dados informados”) ; jTFp . g r a b F o c u s ( ) ;

return; }

S t r i n g l i n h a = ””;

l i n h a = ” S a l t o s PS FaF C1 PS FaF 1ACK PS FaF C1Nova\n”; t ry {

e s c r e v e A r q u i v o . w r i t e (new Date ( ) . t o S t r i n g ( ) + ” / Versao : + v e r s a o+”\n”) ; e s c r e v e A r q u i v o . w r i t e (”h=”+h+”\t r=”+r+”\tp=”+p+”\tq=”+q+”\t f=”+f+”\n”) ; e s c r e v e A r q u i v o . w r i t e ( l i n h a ) ;

} catch ( I O E x c e p t i o n e x ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g (t h i s, ”Erro de s a´ı d a de dados +

”C´odigo PorFormula escreveArquivo . w ri te ( ) ”) ; e x . p r i n t S t a c k T r a c e ( ) ;

}

f o r (i n t i = 3 ; i <= h ; i ++) { PS C1Nova = 0 ;

PS C1 = 1 ( Math . pow ( ( 1 p f q ) , ( r + 1 ) ) ) ;

f o r (i n t j = 0 ; j <= r ; j ++) {

PS C1Nova += p∗f∗q Math . pow((1−p)+p∗f∗(1−q ) , j ) ; }

PS FaF C1Nova = Math . pow ( PS C1Nova , i ) ;

PS FaF C1 = Math . pow ( PS C1 , i ) ;

PS FaF 1ACK = 1−(Math . pow ( ( 1 Math . pow ( p , i )∗Math . pow ( q , i )∗Math . pow ( f , ( 2i ) ) ) , ( r + 1 ) ) ) ;

l i n h a = i + ” ”+ PS FaF C1 + ” ”+ PS FaF 1ACK + ” ”+ PS FaF C1Nova +”\n”; t ry {

e s c r e v e A r q u i v o . w r i t e ( l i n h a ) ; } catch ( I O E x c e p t i o n e x ) {

JOp tio nPan e . s h o w M e s s a g e D i a l o g (t h i s, ”Erro de s a´ı d a de dados +

”C´odigo PorFormula escreveArquivo . w ri te ( ) ”) ; e x . p r i n t S t a c k T r a c e ( ) ;

} }

JO ptio nPa ne . s h o w M e s s a g e D i a l o g (t h i s, ”Processamento c on clu´ıd o ”) ; }

p u b l i c s t a t i c void main ( S t r i n g a r g s [ ] ) {

j a v a . awt . EventQueue . i n v o k e L a t e r (new Runnable ( ) {

p u b l i c void r u n ( ) {

PorFormula p o r F o r m u l a =new PorFormula ( ) ; p o r F o r m u l a . s e t L o c a t i o n ( 1 0 0 , 1 0 0 ) ;

p o r F o r m u l a . s e t V i s i b l e (true) ; }

}) ; }

F i l e d i r e t o r i o C o r r e n t e = n u l l; }

Apˆ endice B

C´ odigos da Implementa¸ c˜ ao do CTCP

Anexo B.1: C´odigo Fonte do CTCP com N´ıvel 2 de Confiabilidade

i n c l u d e s CTCP ; i n c l u d e s CTCPCmd;

i n c l u d e s ACK;

i n c l u d e s TosTime ;

module CTCP {

p r o v i d e s {

i n t e r f a c e S t d C o n t r o l ; } u s e s {

i n t e r f a c e ADC;

i n t e r f a c e Timer ;

//Um t e m p o r i z a d o r p a r a c a d a p o s i c a o do b u f f e r d e t r a n s m i s s a o i n t e r f a c e Timer a s Temp 0 ;

i n t e r f a c e Timer a s Temp 1 ; i n t e r f a c e Timer a s Temp 2 ; i n t e r f a c e Timer a s Temp 3 ; i n t e r f a c e Timer a s Temp 4 ; i n t e r f a c e Timer a s Temp 5 ; i n t e r f a c e Timer a s Temp 6 ; i n t e r f a c e Timer a s Temp 7 ; i n t e r f a c e Timer a s Temp 8 ; i n t e r f a c e Timer a s Temp 9 ; i n t e r f a c e Timer a s T e m p I n i c i a l ; i n t e r f a c e Timer a s Temp Mata no ; i n t e r f a c e L e d s ;

i n t e r f a c e S t d C o n t r o l a s S o u n d e r ; i n t e r f a c e Send ;

i n t e r f a c e SendMsg a s SendACK ; i n t e r f a c e R e c e i v e a s B c a s t ; i n t e r f a c e R e c e i v e M s g a s RecACK ; i n t e r f a c e R o u t e C o n t r o l ;

i n t e r f a c e I n t e r c e p t ; }}

i m p l e m e n t a t i o n { enum {

TAM VET = 1 0 0 ,

NUM MSG = 1 7 , // numero d e m e n s a g e n s g e r a d a s

TAMANHO DO BUFFER = 1 0 ,

TEMPO INICIAL= 1 0 2 4∗1 7 0 , // Tempo n e c e s s ´a r i o p a r a o r o t e a m e n t o c o n v e r g i r

RETRANS PERMIT = 1 0 , // n´umero d e r e t r a n s m i s s ˜o e s

RTT INICIAL = 4 7 , // V a l o r i n i c i a l do t e m p o r i z a d o r

NUM NODES = 2 5 ,

END SOURCE = 0 x0018 , // 25 n o s

//END SOURCE = 0 x 0 0 3 0 , / / 4 9 n o s

//END SOURCE = 0 x 0 0 6 3 , }; / / 1 0 0 n o s // a t e n ¸c ˜a o ao numero d e n ´o s a c i m a /∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

f l o a t a l f a = 0 . 7 ; f l o a t b e t a = 1 . 1 ; f l o a t gama = 1 . 5 ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

f l o a t a l f a 2 = 0 . 1 ; f l o a t b e t a 2 = 1 . 3 ; f l o a t gama2 = 1 . 5 ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

i n t c o n t a p e r c =1; // c o n t a q u a n t a s v e z e s o t e m p o r i z a d o r m a t a n o v a i e s t o u r a r b o o l r e b r o a d c a s t a d c p a c k e t ;

TOS Msg g M s g B u f f e r ;

n o r a c e u i n t 1 6 t g S e n s o r D a t a ; // p r o t e g i d a p o r g f S e n d B u s y f l a g b o o l g f S e n d B u s y ;

TOS Msg t e s t e ; TOS Msg mACK2;

ACKMsg ∗pACK2 ;

CTCPsg m s g r e t r a n s ; // mensagem r e c u p e r a d a do b u f f e r p a r a s e r r e t r a n s m i t i d a TOS Msg g M s g B u f f e r 2 ; // Para u s a r o g e t b u f f e r na r e t r a n s m i s s ˜a o

CTCPsg B u f f e r T r a n s m [ TAMANHO DO BUFFER ] ; // b u f f e r d e t r a n s m i s s ˜a o da camada d e t r a n s p o r t e i n t l i v r e =0; // p r i m e i r a p o s i ¸c ˜a o l i v r e no v e t o r

i n t g u a r d a r e t r a n s R E I N I C [ TAMANHO DO BUFFER ] ; // a r m a z e n a q u a n t a s v e z e s e s t a msg f o i r e t r a n s m i t i d a i n t guardanumseqACK2 [ TAM VET ] ; // a r m a z e n a a s m e n s a g e n s q u e j ´a r e c e b e r a m ACK2 i n t guardaACK1 [ TAMANHO DO BUFFER ] ; // g u a r d a s e a msg j ´a r e c e b e u a c k 1 ou ao f l o a t h o r a g e r a c a o [ TAMANHO DO BUFFER ] ; // g u a r d a a h o r a em q u e a msg f o i g e r a d a f l o a t h o r a a c k [ TAMANHO DO BUFFER ] ; // g u a r d a a h o r a em q u e s e u ACK1 c h e g o u f l o a t h o r a a c k 2 [ TAMANHO DO BUFFER ] ; // g u a r d a a h o r a em q u e s e u ACK2 c h e g o u

i n t g u a r d a t e m p 1 o u 2 [ TAMANHO DO BUFFER ] ; // g u a r d a s e o t e m p o r i z a d o r f o i i n i c i a d o com RTT1 ou RTT2 i n t g u a r d a r e t r a n s t e m p 2 [ TAMANHO DO BUFFER ] ; // g u a r d a q u a n t a s v e z e s uma msg f o i r e t r a n s p o r c a u s a do a c k 2 i n t g u a r d a r e t r a n s t e m p 1 [ TAMANHO DO BUFFER ] ; // g u a r d a q u a n t a s v e z e s uma msg f o i r e t r a n s p o r c a u s a do a c k 1 i n t v e t l o g [ NUM NODES ] ;

i n t i n d i c e b u f f e r =0;

u i n t 3 2 t RTT=47;

u i n t 3 2 t RTT2= 1 0 2 ;

char t i m e B u f [ 1 2 8 ] ; // h o r a em q u e o ACK c h e g a

char t i m e B u f 2 [ 1 2 8 ] ; // h o r a em q u e c h e g a o ACK2

f l o a t a m o s t r a ; f l o a t a m o s t r a 2 ;

f l o a t RTT prev = 0 . 0 4 5 8 9 8 ; f l o a t RTT prev2 = 0 . 1 ; f l o a t t i m e o u t ; f l o a t s e g p a r a i n t ; u i n t 1 6 t n s ; ACKMsg ∗paux ;

u i n t 1 6 t NumSeq ; i n t e s t o u n o b u f f e r =0;

i n t j a r e c e b i a c k 2 =0;

i n t uva =0;

i n t v =0;

CTCPsg ∗p m s g t r a n s p ; // g u a r d a mensagem i n t e r c e p t a d a

u i n t 1 6 t n o o r i g e m = 9 9 9 ; u i n t 1 6 t u l t i n t e r c e p t ;

u i n t 1 6 t i d r e a d i n g ; // numero d e s e q u e n c i a do p a c o t e

i n t p o s i c a o , p o s i c a o A n t e r i o r ; f l o a t ordemDeGrandeza ; i n t h o r a s , m i n u t o s , s e g u n d o s ; f l o a t i n s t a n t e E n v i o ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

I n i t i a l i z a t i o n

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

s t a t i c void i n i t i a l i z e ( ) { u i n t 1 6 t i ;

t i m e r r a t e = INITIAL TIMER RATE ; a t o m i c g f S e n d B u s y = FALSE ; s l e e p i n g = FALSE ;

r e b r o a d c a s t a d c p a c k e t = FALSE ; f o c u s e d = FALSE ;

n s=r a n d ( ) ;

f o r ( i =0; i<TAMANHO DO BUFFER ; i ++) { guardaACK1 [ i ] = 0 ;

g u a r d a r e t r a n s t e m p 1 [ i ] = 0 ; g u a r d a r e t r a n s t e m p 2 [ i ] = 0 ; } f o r ( i =0; i<NUM MSG; i ++) {

ArmazenaAmostra [ i ] = 0 ; ArmazenaAmostra2 [ i ] = 0 ;

i f ( i<NUM MSG−1){

ArmazenaTimeout2 [ i +1]=0; }}}

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

I n i c i a o t e m p o r i z a d o r

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void I n i c i a t e m p (i n t aux , i n t difACK ) {

g u a r d a t e m p 1 o u 2 [ aux ]= difACK ; // a r m a z e n o s e o temp f o i i n i c i a d o com RTT1 ou RTT2 i f ( aux==0){

c a l l Temp 0 . s t o p ( ) ; i f ( difACK == 1 ) {

c a l l Temp 0 . s t a r t (TIMER ONE SHOT , RTT ) ; } i f ( difACK == 2 ) {

c a l l Temp 0 . s t a r t (TIMER ONE SHOT , RTT2 ) ; } } .

. .

i f ( aux1 ==9){

c a l l Temp 0 . s t o p ( ) ; i f ( difACK == 1 ) {

c a l l Temp 9 . s t a r t (TIMER ONE SHOT , RTT ) ; } i f ( difACK == 2 ) {

c a l l Temp 9 . s t a r t (TIMER ONE SHOT , RTT2 ) ; } } return; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

Armazena

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

i n t Armazena ( CTCPsg ∗pCTCP) { i n t aux2 =0;

i n t i ;

CTCPsg tempS=(CTCPsg )∗pCTCP ; f o r( i =0; i<TAMANHO DO BUFFER ; i ++) {

i f ( tempS . numseq == B u f f e r T r a n s m [ i ] . numseq ) { e s t o u n o b u f f e r =1;

aux2= i ;} } i f ( e s t o u n o b u f f e r ! = 1 ) {

i f ( l i v r e <TAMANHO DO BUFFER) { a t o m i c{

B u f f e r T r a n s m [ l i v r e ] = ( CTCPsg )∗pCTCP ; g u a r d a r e t r a n s R E I N I C [ l i v r e ]= 1 ;

g u a r d a r e t r a n s t e m p 1 [ l i v r e ] = 0 ; g u a r d a r e t r a n s t e m p 2 [ l i v r e ] = 0 ;

aux2= l i v r e ; l i v r e ++; }} e l s e { l i v r e =0;

B u f f e r T r a n s m [ l i v r e ] = ( CTCPsg )∗pCTCP ; g u a r d a r e t r a n s R E I N I C [ l i v r e ]= 1 ; g u a r d a r e t r a n s t e m p 1 [ l i v r e ] = 0 ;

g u a r d a r e t r a n s t e m p 2 [ l i v r e ] = 0 ; aux2= l i v r e ;

l i v r e ++; }}}

return ( aux2 ) ; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

C a l c u l a RTT prev

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

f l o a t C a l c u l a R T T p r e v (i n t d i , i n t paraqualRTT ){

i f( paraqualRTT == 1 ) { i n d i c e ++;

a m o s t r a = h o r a a c k [ d i ] h o r a g e r a c a o [ d i ] ; RTT prev = ( a l f a∗RTT prev )+((1−a l f a )∗a m o s t r a ) ; t i m e o u t = b e t a RTT prev ; }

i f( paraqualRTT == 2 ) { i n d i c e 2 ++;

a m o s t r a 2 = h o r a a c k 2 [ d i ] h o r a g e r a c a o [ d i ] ; RTT prev2 = ( a l f a 2∗RTT prev2 )+((1−a l f a 2 )∗a m o s t r a 2 ) ; t i m e o u t = b e t a 2 RTT prev2 ; }

return t i m e o u t ; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

T r a t a n d o o s ACKs

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

void TrataACK ( ){

i n t i ; CTCPsg temp ;

j a r e c e b i a c k 2 =0;

// v e r i f i c a s e o ACK2 j ´a c h e g o u p a r a e s t a mensagem f o r ( i =0; i<TAM VET ; i ++) {

i f ( guardanumseqACK2 [ i ]==NumSeq ) { j a r e c e b i a c k 2 =1; }}

// R e c e b i o ACK1 , s e a msg n˜ao f o i g e r a d a p o r mim e n v i a r ACK2 i f ( paux−>t y p e ==1) {

c o n t A C K 1 r e c ++;

i f ( j a r e c e b i a c k 2 == 0 ) {

f o r ( i =0; i <TAMANHO DO BUFFER ; i ++) { temp = B u f f e r T r a n s m [ i ] ;

i f ( temp . numseq == NumSeq ) { guardaACK1 [ i ]++;

i f ( g u a r d a r e t r a n s t e m p 1 [ i ]==0){

// h o r a em q u e o ACK c h e g o u p r i n t T i m e ( t i m e B u f , 1 2 8 ) ;

h o r a a c k [ i ]= A l t e r a t e m p o ( t i m e B u f ) ;

a t o m i c{s e g p a r a i n t = 1 0 2 4∗C a l c u l a R T T p r e v ( i , 1 ) ;}

RTT=( u i n t 3 2 t ) s e g p a r a i n t ;} g u a r d a r e t r a n s R E I N I C [ i ] = 1 ;

i f ( temp . o r i g e m a d d r==TOS LOCAL ADDRESS) { P a r a t e m p ( i ) ;

I n i c i a t e m p ( i , 2 ) ; } e l s e{

P a r a t e m p ( i ) ; // p a r a o temp p o i s o a c k 1 c h e g o u I n i c i a t e m p ( i , 2 ) ;

// Monta o p a c o t e do ACK2 pACK2>r e c n u m s e q = NumSeq ; pACK2>t y p e = 2 ;

pACK2>o r i g e m d o a c k=TOS LOCAL ADDRESS ;

i f ( c a l l SendACK . s e n d ( B u f f e r T r a n s m [ i ] . i n t e r c e p t a n t , s i z e o f(ACKMsg ) , &mACK2) ==SUCCESS) { a t o m i c g f S e n d B u s y = FALSE ; } }

i =11; }}}}

// R e c e b i o ACK2 i f ( paux−>t y p e ==2) {

c o n t A C K 2 r e c ++;

i f ( j a r e c e b i a c k 2 == 0 ) { a t o m i c{

guardanumseqACK2 [ uva ]=NumSeq ; // g u a r d a a m s g q u e r e c e b e u o a c k 2 uva++;

f o r ( i =0; i <TAMANHO DO BUFFER ; i ++) { i f ( B u f f e r T r a n s m [ i ] . numseq == NumSeq ) {

P a r a t e m p ( i ) ;

g u a r d a r e t r a n s R E I N I C [ i ] = 0 ; i f ( g u a r d a r e t r a n s t e m p 2 [ i ]==0){

p r i n t T i m e ( t i m e B u f 2 , 1 2 8 ) ;

h o r a a c k 2 [ i ]= A l t e r a t e m p o ( t i m e B u f 2 ) ;

a t o m i c {s e g p a r a i n t = 1 0 2 4∗C a l c u l a R T T p r e v ( i , 2 ) ;}

RTT2=( u i n t 3 2 t ) s e g p a r a i n t ; } i f ( guardaACK1 [ i ]==0) {

pACK2−>r e c n u m s e q = NumSeq ; pACK2−>t y p e = 2 ;

pACK2−>o r i g e m d o a c k=TOS LOCAL ADDRESS ; n a c k 2 ++;

i f ( c a l l SendACK . s e n d ( B u f f e r T r a n s m [ i ] . i n t e r c e p t a n t , s i z e o f(ACKMsg ) , &mACK2) ==SUCCESS) { a t o m i c g f S e n d B u s y = FALSE ; }}

i =(TAMANHO DO BUFFER+ 1 ) ; }}}}}

j a r e c e b i a c k 2 =0; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

T r a t a a s m e n s a g e n s i n t e r c e p t a d a s

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void T r a t a I n t e r c e p t a ( ){

ACKMsg ∗pACK = (ACKMsg ∗) t e s t e . d a t a ; // Monta o p a c o t e do ACK1

t e s t e . t y p e = AM ACKMSG; // s e t a o t i p o d e mensagem no c a b e ¸c a l h o TOS Msg t e s t e . a d d r = u l t i n t e r c e p t ;

t e s t e . l e n g t h = s i z e o f( t e s t e . d a t a ) ; pACK>r e c n u m s e q = i d r e a d i n g ; pACK>t y p e = 1 ;

pACK>o r i g e m d o a c k= TOS LOCAL ADDRESS ; n a c k++;

// E n v i a o ACK1 p a r a o n´o d e o r i g e m

i f ( c a l l SendACK . s e n d ( u l t i n t e r c e p t , s i z e o f(ACKMsg ) , &t e s t e ) == SUCCESS) { a t o m i c g f S e n d B u s y = FALSE ;}

// Se f o r o n´o z e r o e l e t e r a q u e mandar um ACK1 e um ACk2 ao mesmo t e m p o i f (TOS LOCAL ADDRESS == 0 x 0 0 0 0 ) {

a t o m i c g f S e n d B u s y = TRUE;

t e s t e . t y p e = AM ACKMSG; // s e t a o t i p o d e mensagem no c a b e ¸c a l h o TOS Msg t e s t e . a d d r = u l t i n t e r c e p t ;

t e s t e . l e n g t h = s i z e o f( t e s t e . d a t a ) ; pACK>r e c n u m s e q = i d r e a d i n g ; pACK>t y p e = 2 ;

pACK>o r i g e m d o a c k= TOS LOCAL ADDRESS ;

i f ( c a l l SendACK . s e n d ( u l t i n t e r c e p t , s i z e o f(ACKMsg ) , &t e s t e ) == SUCCESS) { a t o m i c g f S e n d B u s y = FALSE ; }}

c o n t i n t e r c e p t ++; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

E n v i a mensagem

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

t a s k void SendData ( ) { CTCPsg ∗p R e a d i n g ;

u i n t 1 6 t Len ;

// C r i a n d o uma mensagem d e t r a n s p o r t e p a r a e n v i a r .

i f ( p R e a d i n g = ( ( CTCPsg ∗) ( c a l l Send . g e t B u f f e r (& g M s g B u f f e r ,& Len ) ) ) ) { pReading−>t y p e = CTCP TYPE SENSORREADING ;

pReading−>p a r e n t a d d r = c a l l R o u t e C o n t r o l . g e t P a r e n t ( ) ; pReading−>r e a d i n g = g S e n s o r D a t a ;

pReading−>o r i g e m a d d r = TOS LOCAL ADDRESS ; pReading−>i n t e r c e p t a d d r = TOS LOCAL ADDRESS ; pReading−>i n t e r c e p t a n t = TOS LOCAL ADDRESS ; pReading−>numseq = n s ;

n s ++; // numero d e s e q u e n c i a

c o n t ++; // numero d e msg c r i a d a s p e l o o c o r r e n t e

// Armazenando a mensagem no b u f f e r d e t r a n s p o r t e a n t e s d e e n v i a r i n d i c e b u f f e r =Armazena ( p R e a d i n g ) ;

// h o r a em q u e a msg f o i g e r a d a p r i n t T i m e ( t i m e B u f , 1 2 8 ) ;

h o r a g e r a c a o [ i n d i c e b u f f e r ]= A l t e r a t e m p o ( t i m e B u f ) ; // E n v i a n d o a msg j ´a a r m a z e n a d a em b u f f e r

i f ( ( c a l l Send . s e n d (& g M s g B u f f e r ,s i z e o f( CTCPsg ) ) ) == SUCCESS) {

a t o m i c g f S e n d B u s y = FALSE ; // e s t a l i n h a nao e x i s t e na c o n f 1 // I n i c i a r o t e m p o r i z a d o r a c a d a msg e n v i a d a menos o no z e r o

i f (TOS LOCAL ADDRESS != 0 x 0 0 0 0 ) {

I n i c i a t e m p ( i n d i c e b u f f e r , 1 ) ; } } e l s e { a t o m i c g f S e n d B u s y = FALSE ; }}}

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

R e t r a n s m i t e

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void R e t r a n s m i t e (i n t i n d i c e r e t r a n s , i n t e s t o u r o d e q u e m ) { u i n t 1 6 t Len2 ;

CTCPsg ∗p R e a d i n g 2 ; i n t p r o i b i d o =0;

// P e g a n d o a msg c o r r e s p o n d e n t e ao i n d i c e r e t r a n s m s g r e t r a n s = B u f f e r T r a n s m [ i n d i c e r e t r a n s ] ;

// Se e s t a r e s t r a n s m i s s a o f o i g e r a d a p o r um e s t o u r o do RTT2 o gamma n˜ao d e v e s e r u s a d o i f ( e s t o u r o d e q u e m ==1) {

g u a r d a r e t r a n s t e m p 1 [ i n d i c e r e t r a n s ]++;

RTT = gama∗RTT;} i f ( e s t o u r o d e q u e m ==2) {

// A l t e r a n d o o v a l o r do t i m e o u t p o r c a u s a do a l g o r i t m o d e k a r n g u a r d a r e t r a n s t e m p 2 [ i n d i c e r e t r a n s ]++;

RTT2 = gama∗RTT2 ;}

// V e r i f i c a n d o umero d e v e z e s q u e a msg f o i r e t r a n s m i t i d a i f ( g u a r d a r e t r a n s R E I N I C [ i n d i c e r e t r a n s ]<RETRANS PERMIT) {

g u a r d a r e t r a n s R E I N I C [ i n d i c e r e t r a n s ] = g u a r d a r e t r a n s R E I N I C [ i n d i c e r e t r a n s ] + 1 ; } e l s e {p r o i b i d o =1;}

// r e t r a n s m i t i n d o i f ( p r o i b i d o ! = 1 ) {

i f ( p R e a d i n g 2 = ( CTCPsg ∗) ( c a l l Send . g e t B u f f e r (& g M s g B u f f e r 2 ,& Len2 ) ) ) { pReading2−>t y p e = m s g r e t r a n s . t y p e ;

pReading2−>p a r e n t a d d r = c a l l R o u t e C o n t r o l . g e t P a r e n t ( ) ; pReading2−>r e a d i n g = m s g r e t r a n s . r e a d i n g ;

pReading2−>o r i g e m a d d r = m s g r e t r a n s . o r i g e m a d d r ; pReading2−>numseq = m s g r e t r a n s . numseq ;

pReading2−>i n t e r c e p t a d d r = m s g r e t r a n s . i n t e r c e p t a d d r ; pReading2−>i n t e r c e p t a n t = m s g r e t r a n s . i n t e r c e p t a n t ; c o n t r e t r a n s ++;

i f ( ( c a l l Send . s e n d (& g M s g B u f f e r 2 ,s i z e o f( CTCPsg ) ) ) == SUCCESS) { a t o m i c g f S e n d B u s y = FALSE ;

I n i c i a t e m p ( i n d i c e r e t r a n s , 1 ) ; } e l s e { a t o m i c g f S e n d B u s y = FALSE ; } e l s e { dbg ( DBG USR3 , E r r o” ) ; }}

p r o i b i d o =0;

atomic gfSendBusy = FALSE;

return ; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

command r e s u l t t StdControl . i n i t ( ) { i n i t i a l i z e ( ) ;

return SUCCESS;}

command r e s u l t t StdControl . s t a r t ( ) {

return c a l l Temp Inicial . s t a r t (TIMER ONE SHOT, TEMPO INICIAL) ; } command r e s u l t t StdControl . stop ( ) {

return c a l l Timer . stop ( ) ; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

Eventos

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t Timer . f i r e d ( ) {

i f ( cont<15){ //para e n v i a r 15 msg cont v a i de zero a 14 i f (TOS LOCAL ADDRESS == END SOURCE) {

c a l l ADC. getData ( ) ; }}

return SUCCESS;}

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

Temporizador i n i c i a l

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t Temp Inicial . f i r e d ( ) {

return c a l l Timer . s t a r t (TIMER REPEAT, t i m e r r a t e ) ; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

TEMPORIZADORES

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t Temp 0 . f i r e d ( ) { atomic {

i f ( ! gfSendBusy ) { i n d i c e b u f f e r =0;

gfSendBusy = TRUE;

i f ( guardatemp1ou2 [ i n d i c e b u f f e r ]==1){

Retransmite ( i n d i c e b u f f e r , 1 ) ; } i f ( guardatemp1ou2 [ i n d i c e b u f f e r ]==2){

Retransmite ( i n d i c e b u f f e r , 2 ) ; } }}

return SUCCESS; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

. . .

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t Temp 9 . f i r e d ( ) { atomic {

i f ( ! gfSendBusy ) { i n d i c e b u f f e r =9;

gfSendBusy = TRUE;

i f ( guardatemp1ou2 [ i n d i c e b u f f e r ]==1){

Retransmite ( i n d i c e b u f f e r , 1 ) ; } i f ( guardatemp1ou2 [ i n d i c e b u f f e r ]==2){

Retransmite ( i n d i c e b u f f e r , 2 ) ; } }}

return SUCCESS; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t Send . sendDone (TOS MsgPtr pMsg, r e s u l t t s u c c e s s ) { atomic gfSendBusy = FALSE;

return SUCCESS; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t SendACK. sendDone (TOS MsgPtr pMsg, r e s u l t t s u c c e s s ) { atomic gfSendBusy = FALSE;

return SUCCESS; }

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

Interceptando uma mensagem

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event r e s u l t t I n t e r c e p t . i n t e r c e p t (TOS MsgPtr msg , void∗ payload , u i n t 1 6 t payloadLen ) { pmsg transp = (CTCPsg∗) payload ;

printTime ( timeBuf , 1 2 8 ) ;

// l ˆe o n´o origem da mensagem e o num de sequencia no origem = pmsg transp−>origemaddr ;

i d r e a d i n g = pmsg transp−>numseq ;

u l t i n t e r c e p t = pmsg transp−>i n t e r c e p t a d d r ; // Altera o campo i n t e r c e p t a d d r da msg i n t e r c e p t a d a pmsg transp−>i n t e r c e p t a n t = pmsg transp−>i n t e r c e p t a d d r ; pmsg transp−>i n t e r c e p t a d d r = TOS LOCAL ADDRESS;

// I n i c i a a t a r e f a que v a i gerar os ACKs TrataIntercepta ( ) ;

//Guarda a mensagem i n t e r c e p t a d a no cache i n d i c e b u f f e r=Armazena( pmsg transp ) ; i f ( e s t o u n o b u f f e r==1) {

atomic e s t o u n o b u f f e r =0;

return FAIL ; } e l s e {// e s t a l i n h a f a z com que a mensagem n˜ao s e j a reencaminhada i f (TOS LOCAL ADDRESS != 0x0000 ){

I n i c i a t e m p ( i n d i c e b u f f e r , 1 ) ;}

printTime ( timeBuf , 1 2 8 ) ;

hora geracao [ i n d i c e b u f f e r ]=Altera tempo ( timeBuf ) ;

return SUCCESS; }} // e s t a l i n h a f a z com que a mensagem s e j a reencaminhada /∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

P r e c i s o receber os ACKs

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

event TOS MsgPtr RecACK. r e c e i v e (TOS MsgPtr pMsg) {

i f (pMsg>addr==TOS LOCAL ADDRESS) { //o ack ´e enderecado para e s t e no atomic {

pACK2 = (ACKMsg∗)mACK2. data ; paux = (ACKMsg ∗)pMsg>data ; NumSeq = paux−>recnumseq ; TrataACK ( ) ; }}

return pMsg ; } }

Anexo B.2: C´odigo Fonte do CTCP com N´ıvel 1 de Confiabilidade e Controle de Congestionamento

i n c l u d e s CTCP ; i n c l u d e s CTCPCmd;

i n c l u d e s ACK;

i n c l u d e s TosTime ;

module CTCPM {

p r o v i d e s {

i n t e r f a c e S t d C o n t r o l ;}

u s e s {

i n t e r f a c e ADC;

i n t e r f a c e Timer ;

//Um t e m p o r i z a d o r p a r a c a d a p o s i c a o do b u f f e r d e t r a n s m i s s a o i n t e r f a c e Timer a s Temp 0 ;

i n t e r f a c e Timer a s Temp 1 ; i n t e r f a c e Timer a s Temp 2 ; i n t e r f a c e Timer a s Temp 3 ; i n t e r f a c e Timer a s Temp 4 ; i n t e r f a c e Timer a s Temp 5 ; i n t e r f a c e Timer a s Temp 6 ; i n t e r f a c e Timer a s Temp 7 ; i n t e r f a c e Timer a s Temp 8 ; i n t e r f a c e Timer a s Temp 9 ; i n t e r f a c e Timer a s T e m p I n i c i a l ; i n t e r f a c e Timer a s Temp START ; i n t e r f a c e L e d s ;

i n t e r f a c e S t d C o n t r o l a s S o u n d e r ; i n t e r f a c e Send ;

i n t e r f a c e SendMsg a s SendACK ; i n t e r f a c e R e c e i v e a s B c a s t ; i n t e r f a c e R e c e i v e M s g a s RecACK ; i n t e r f a c e R o u t e C o n t r o l ;

i n t e r f a c e I n t e r c e p t ; i n t e r f a c e Time ; i n t e r f a c e T i m e U t i l ; }}

i m p l e m e n t a t i o n { enum {

TAMANHO DO BUFFER = 1 0 ,

TAM VET = 2 6 , // n´umero d e m e n s a g e n s e n v i a d a s

PATAMAR = 6 , //pATAMAR

RETRANS PERMIT = 1 0 , // s i g n i f i c a n o v e r e t r a n s m i s s ˜o e s

NUM NODES = 2 5 ,

RTT INICIAL = 4 7 , // t i r e i do l o g RTT 3

END SOURCE = 0 x0018 , // 25 n o s

//END SOURCE = 0 x 0 0 3 0 , / / 4 9 n o s

//END SOURCE = 0 x 0 0 6 3 , / / 1 0 0 n o s // a t e n ¸c ˜a o ao numero d e n ´o s a c i m a

//END SOURCE = 0 X0004 ,};

i n t c o n t a p e r c =1; // c o n t a q u a n t a s v e z e s o t e m p o r i z a d o r m a t a n o v a i e s t o u r a r b o o l r e b r o a d c a s t a d c p a c k e t ;

TOS Msg g M s g B u f f e r ;

n o r a c e u i n t 1 6 t g S e n s o r D a t a ; // p r o t e g i d a p o r g f S e n d B u s y f l a g b o o l g f S e n d B u s y ;

TOS Msg t e s t e ;

CTCPMsg m s g r e t r a n s ; // mensagem r e c u p e r a d a do b u f f e r p a r a s e r r e t r a n s m i t i d a

TOS Msg g M s g B u f f e r 2 ; // Para u s a r o g e t b u f f e r na r e t r a n s m i s s ˜a o

CTCPMsg B u f f e r T r a n s m [ TAMANHO DO BUFFER ] ; // b u f f e r d e t r a n s m i s s ˜a o da camada d e t r a n s p o r t e

i n t l i v r e =0; // p r i m e i r a p o s i ¸c ˜a o l i v r e no v e t o r i n t quantnumseq [ TAMANHO DO BUFFER ] ; // a r m a z e n a o i n s t a n t e d e e n v i o d e c a d a msg f l o a t h o r a g e r a c a o [ TAMANHO DO BUFFER ] ; // g u a r d a a h o r a em q u e a msg f o i g e r a d a f l o a t h o r a a c k [ TAMANHO DO BUFFER ] ; // g u a r d a a h o r a em q u e s e u ACK c h e g o u

i n t f o i p r o c e s s a d a [ TAMANHO DO BUFFER ] ; // i n d i c a s e a msg f o i p r o c e s s a d a ou ao p e l o noh

i n t p e r d a =0; // c o n t a q u a n t a s msg f o r a m s o b r e p o s t a s sem s e r e m p r o c e s s a d a s u i n t 1 6 t o r i g e n s [ TAMANHO DO BUFFER ] ; // g u a r d a e n d e r e ¸c o s d e o r i g e n s c o n t i d a s no b u f

i n t i n d i c e b u f f e r =0;

u i n t 3 2 t RTT;

u i n t 1 6 t n s ; u i n t 1 6 t n s 1 ;

u i n t 3 2 t RTTSTART= 1 0 2 4 ; ACKMsg ∗paux ;

u i n t 1 6 t NumSeq ; i n t e s t o u n o b u f f e r =0;

char t i m e B u f [ 1 2 8 ] ; i n t m s g p r o c e s s a d a s =0;

i n t p o s o c u p a d a s =0;

i n t e n v i o u s t o p =0;

CTCPMsg m s g t r a n s ; // mensagem do b u f f e r q u e v a i s e r t r a n s m p e l a p r i m e i r a v e z i n t s t a t u s d o N O =0;

TOS Msg g M s g B u f f e r 3 ; f l o a t a m o s t r a ;

f l o a t RTT prev = 0 . 0 4 5 8 9 8 ; f l o a t t i m e o u t ;

f l o a t s e g p a r a i n t ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

f l o a t a l f a = 0 . 7 ; f l o a t b e t a = 1 . 1 ;

// f l o a t gama = 1 . 5 ; // u s a d o a n t e s do CC f l o a t gama =1; // u s a d o p a r a CC

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

i n t i n d i c e =0; // i n d i c e d o s d o i s p r ´o x i m o s v e t o r e s f l o a t ArmazenaAmostra [ TAM VET ] ;

f l o a t ArmazenaTimeout [ TAM VET ] ; u i n t 1 6 t ArmazenaNumSeq [ TAM VET ] ; i n t uva =0;

i n t p o s i c a o , p o s i c a o A n t e r i o r ; // p o s i c a o ( e p o s i c a o a n t e r i o r ) em um a r r a y ( v e t o r ) f l o a t ordemDeGrandeza ; // a u x i l i a r p / r e t i r a r m i n u t o s d e t i m e B u f

i n t h o r a s , m i n u t o s , s e g u n d o s ; f l o a t i n s t a n t e E n v i o ;

u i n t 1 6 t v i z i n h o s D e v o S t a r t [ TAM VET ] ; // V i z i n h o s p a r a o n d e a l g u m a v e z j a h // e n v i e i STOP . D e v i d o ao c e n ´a r i o e s t ´a t i c o da r e d e , o v e t o r a c i m a ao ´e r e s e t a d o . i n t q t d V i z i n h o s D e v o S t a r t = 0 ;

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

I n i t i a l i z a t i o n

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

s t a t i c void i n i t i a l i z e ( ) { t i m e r r a t e = INITIAL TIMER RATE ; a t o m i c g f S e n d B u s y = FALSE ; s l e e p i n g = FALSE ;

r e b r o a d c a s t a d c p a c k e t = FALSE ; f o c u s e d = FALSE ;

RTT=RTT INICIAL ;

dbg ( DBG USR3 , ”%d : O v a l o r do RTT ao i n i c i a r o programa eh:%d\n”,TOS LOCAL ADDRESS , RTT ) ; ArmazenaAmostra [ 0 ] = 0 ;

ArmazenaTimeout [ 0 ] =RTT;

ArmazenaNumSeq [ 0 ] = 0 ; n s 1=r a n d ( ) ;

n s=n s 1 ;}

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

I n i c i a o t e m p o r i z a d o r

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void I n i c i a t e m p (i n t aux ) { i f ( aux==0){

c a l l Temp 0 . s t a r t (TIMER ONE SHOT , RTT) ;}

. . .

i f ( aux==9){

c a l l Temp 9 . s t a r t (TIMER ONE SHOT , RTT ) ; } return; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

ara o t e m p o r i z a d o r

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void P a r a t e m p (i n t aux1 ) { i f ( aux1 ==0){

c a l l Temp 0 . s t o p ( ) ; } .

. .

i f ( aux1 ==9){

c a l l Temp 9 . s t o p ( ) ; } return; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

E n v i a ACK

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void EnviaACK (i n t t i p o , u i n t 1 6 t paraquem , u i n t 1 6 t numS ) { ACKMsg ∗pACK = (ACKMsg ∗) t e s t e . d a t a ;

// Monta o p a c o t e do ACK( 1 ) ou ACK STOP ( 3 ) ou s t a r t ( 4 )

t e s t e . t y p e = AM ACKMSG; // s e t a o t i p o d e mensagem no c a b e ¸c a l h o TOS Msg t e s t e . a d d r = paraquem ;

t e s t e . l e n g t h = s i z e o f( t e s t e . d a t a ) ; pACK>r e c n u m s e q = numS ;

i f ( t i p o ==1){pACK>t y p e = 1 ;}

i f ( t i p o ==3){pACK>t y p e = 3 ;}

i f ( t i p o ==4){pACK>t y p e = 4 ;}

n a c k++; // c o n t a numero d e a c k s t r a n s m i t i d o s // E n v i a o ACK p a r a o n´o d e o r i g e m

i f ( c a l l SendACK . s e n d ( paraquem , s i z e o f(ACKMsg ) , &t e s t e ) == SUCCESS) { a t o m i c g f S e n d B u s y = FALSE ; } }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

V e r i f i c a B u f

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void V e r i f i c a B u f (i n t quemchamouArmazena , u i n t 1 6 t e n d e r e c o , u i n t 1 6 t s e q u e n c i a ) { i n t i , c , c 1 ;

i n t a c h e i n u m s e q s t o p =0;

// quemchamouArmazena p o d e s e r : // 1 S e n d D a t a c r i a n d o msg // 2 I n t e r c e p t a msg

// 3 R e c e b e u ACK1 // 4 t e m p o r i z a d o r

// m s g p r o c e s s a d a s e h o num d e m e n s a g e n s q u e j a h f o r a m p r o c e s s a d a s e podem s e r s o b r e p o s t a s m s g p r o c e s s a d a s =0;

p o s o c u p a d a s =0;

f o r( i =0; i<TAMANHO DO BUFFER ; i ++) { i f ( f o i p r o c e s s a d a [ i ]==1) {

m s g p r o c e s s a d a s=m s g p r o c e s s a d a s +1; } i f ( f o i p r o c e s s a d a [ i ]==2) {

p o s o c u p a d a s=p o s o c u p a d a s +1; }}

i f ( quemchamouArmazena ==1) {

// q u a n d o quemchamouArmazena==1 n˜ao p o s s o e n v i a r nenhum // t i p o d e a c k p o i s f o i o p r o p r i o no q u e g e r o u

dbg ( DBG USR3 , ”%d : Armazena : N˜ao e n v i e i ACK porque estou CRIANDO\n”,TOS LOCAL ADDRESS ) ;}

i f ( quemchamouArmazena ==2) {

// Se o num d e p o s i c o e s o c u p a d a s f o r m a i o r ou i g u a l ao p a t a m a r i f ( p o s o c u p a d a s>=PATAMAR) {

dbg ( DBG USR3 , ”%d : Armazena : ENVIAR STOP\n”,TOS LOCAL ADDRESS ) ; // e n v i a r s t o p t i p o 3

// p a r o o t e m p o r i z a d o r do s t a r t c a l l Temp START . s t o p ( ) ;

// E n v i a s t o p , q u e e h um ACK t i p o 3

EnviaACK ( 3 , e n d e r e c o , s e q u e n c i a ) ; a t o m i c e n v i o u s t o p =1;

// v e r i f i c a s e a o r i g e m j a h e s t a no v e t o r f o r( i =0; i<q t d V i z i n h o s D e v o S t a r t ; i ++) {

i f ( e n d e r e c o == v i z i n h o s D e v o S t a r t [ i ] ) { u m s e q s t o p =1;

i =q t d V i z i n h o s D e v o S t a r t ; } } // g u a r d a r no v e t o r d e s t o p i f( a c h e i n u m s e q s t o p ==0) {

v i z i n h o s D e v o S t a r t [ q t d V i z i n h o s D e v o S t a r t ++]= e n d e r e c o ; }}e l s e { // s e ao e n v i o u o s t o p d e v o e n v i a r um a c k n o r m a l

EnviaACK ( 1 , e n d e r e c o , s e q u e n c i a ) ; } } i f ( quemchamouArmazena ==3) {

// quemchamou f o i o T e m p o r i z a d o r

// Se o num d e p o s i c o e s o c u p a d a s f o r menor q u e o p a t a m a r e n v i a s t a r t i f ( p o s o c u p a d a s<(PATAMAR−2)) {

i f ( e n v i o u s t o p ==1){

f o r( c =0; c<q t d V i z i n h o s D e v o S t a r t ; c++) {

EnviaACK ( 4 , v i z i n h o s D e v o S t a r t [ c ] , s e q u e n c i a ) ; } c a l l Temp START . s t a r t (TIMER REPEAT, RTTSTART ) ; a t o m i c e n v i o u s t o p =0; }}}

i f ( quemchamouArmazena ==4) { // quemchamou f o i o ACK1

// Se o num d e p o s i c o e s o c u p a d a s f o r menor q u e o p a t a m a r e n v i a s t a r t s e n ˜a o ao f a z n a d a i f ( p o s o c u p a d a s<(PATAMAR−2)) {

dbg ( DBG USR3 , ”%d : Armazena : ENVIAR START MOTIVO 4\n”,TOS LOCAL ADDRESS ) ; // e n v i a r s t a r t t i p o 4

f o r( c 1 =0; c1<q t d V i z i n h o s D e v o S t a r t ; c 1++) {

EnviaACK ( 4 , v i z i n h o s D e v o S t a r t [ c 1 ] , s e q u e n c i a ) ; } c a l l Temp START . s t a r t (TIMER REPEAT, RTTSTART ) ; } return; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

Armazena

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

i n t Armazena (CTCPMsg ∗pCTCP, i n t quemchamou ) { i n t a c h e i p o s L i v r e =0;

i n t aux2 =0;

i n t i ;

CTCPMsg tempS=(CTCPMsg)∗pCTCP ; f o r( i =0; i<TAMANHO DO BUFFER ; i ++) {

i f ( tempS . numseq == B u f f e r T r a n s m [ i ] . numseq ) { a t o m i c e s t o u n o b u f f e r =1;

aux2= i ;

EnviaACK ( 1 , B u f f e r T r a n s m [ i ] . i n t e r c e p t a n t , B u f f e r T r a n s m [ i ] . numseq ) ; }}

i f ( e s t o u n o b u f f e r ! = 1 ) {

// s e amsg n˜ao e s t a no b u f f e r d e v o a r m a z e n a l a a t o m i c {

f o r( i =0; i<TAMANHO DO BUFFER ; i ++) {

i f ( f o i p r o c e s s a d a [ i ]==1 | | f o i p r o c e s s a d a [ i ]==0) { // a msg j a h f o i p r o c e s s a d a l i v r e = i ;

i =TAMANHO DO BUFFER+1;

a c h e i p o s L i v r e =1; }}

i f ( a c h e i p o s L i v r e ==0) { l i v r e =0; } a c h e i p o s L i v r e =0; }

i f ( f o i p r o c e s s a d a [ l i v r e ]==2){

p e r d a ++; }

B u f f e r T r a n s m [ l i v r e ] = (CTCPMsg)∗pCTCP ; quantnumseq [ l i v r e ]= 1 ;

f o i p r o c e s s a d a [ l i v r e ] = 2 ;

// t o d a v e z q u e uma n o v a msg ´e a r m a z e n a d a e l a r e c e b e f o i p r o c e s s a d a i g u a l a 2 i f (TOS LOCAL ADDRESS == 0 0 0 0 ){

f o i p r o c e s s a d a [ l i v r e ] = 1 ; } aux2= l i v r e ;

V e r i f i c a B u f ( quemchamou , B u f f e r T r a n s m [ aux2 ] . i n t e r c e p t a n t , B u f f e r T r a n s m [ aux2 ] . numseq ) ; }

return ( aux2 ) ; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

C a l c u l a RTT prev

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

f l o a t C a l c u l a R T T p r e v (i n t d i ){

i n d i c e ++;

a m o s t r a = h o r a a c k [ d i ] h o r a g e r a c a o [ d i ] ; RTT prev = ( a l f a∗RTT prev )+((1a l f a )∗a m o s t r a ) ; t i m e o u t = b e t a RTT prev ;

return t i m e o u t ; }

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

S e n d D a t a ( ) G e r a c a o d e msg

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

t a s k void SendData ( ) { CTCPMsg ∗p R e a d i n g ;

u i n t 1 6 t Len ;

// C r i a n d o uma mensagem d e t r a n s p o r t e p a r a e n v i a r .

i f ( p R e a d i n g = ( ( CTCPMsg ∗) ( c a l l Send . g e t B u f f e r (& g M s g B u f f e r ,& Len ) ) ) ) { pReading−>t y p e = CTCP TYPE SENSORREADING ;

pReading−>p a r e n t a d d r = c a l l R o u t e C o n t r o l . g e t P a r e n t ( ) ; pReading−>r e a d i n g = g S e n s o r D a t a ;

pReading−>o r i g e m a d d r = TOS LOCAL ADDRESS ; pReading−>i n t e r c e p t a d d r = TOS LOCAL ADDRESS ; pReading−>i n t e r c e p t a n t = TOS LOCAL ADDRESS ; pReading−>numseq = n s ;

pReading−>I D c o n e x = n s 1 ; n s ++; // numero d e s e q u e n c i a

c o n t ++; // numero d e msg c r i a d a s p e l o o c o r r e n t e

// Armazenando a mensagem no b u f f e r d e t r a n s p o r t e a n t e s d e e n v i a r i n d i c e b u f f e r =Armazena ( pReading , 1 ) ;

// h o r a em q u e a msg f o i g e r a d a p r i n t T i m e ( t i m e B u f , 1 2 8 ) ;

h o r a g e r a c a o [ i n d i c e b u f f e r ]= A l t e r a t e m p o ( t i m e B u f ) ; i f ( s t a t u s d o N O == 0 ) {

i f ( ( c a l l Send . s e n d (& g M s g B u f f e r ,s i z e o f(CTCPMsg ) ) ) == SUCCESS) { i f (TOS LOCAL ADDRESS != 0 0 0 0 ) {

I n i c i a t e m p ( i n d i c e b u f f e r ) ; } e l s e { a t o m i c g f S e n d B u s y = FALSE ; } e l s e { a t o m i c g f S e n d B u s y = FALSE ; }}}

/∗ ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗

R e t r a n s m i t e

∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ ∗/

void R e t r a n s m i t e (i n t i n d i c e r e t r a n s ) { u i n t 1 6 t Len2 ;

CTCPMsg ∗p R e a d i n g 2 ; i n t p r o i b i d o =0;

// P e g a n d o a msg c o r r e s p o n d e n t e ao i n d i c e r e t r a n s m s g r e t r a n s = B u f f e r T r a n s m [ i n d i c e r e t r a n s ] ;

// A l t e r a n d o o v a l o r do t i m e o u t p o r c a u s a do a l g o r i t m o d e k a r n RTT = gama∗RTT;

// V e r i f i c a n d o umero d e v e z e s q u e a msg f o i r e t r a n s m i t i d a i f ( quantnumseq [ i n d i c e r e t r a n s ]<RETRANS PERMIT) {

quantnumseq [ i n d i c e r e t r a n s ] = quantnumseq [ i n d i c e r e t r a n s ] + 1 ; } e l s e { p r o i b i d o =1; }

i f ( p r o i b i d o ! = 1 ) {

i f ( s t a t u s d o N O==0) {

i f ( p R e a d i n g 2 = (CTCPMsg ) ( c a l l Send . g e t B u f f e r (& g M s g B u f f e r 2 ,& Len2 ) ) ) { pReading2−>t y p e = m s g r e t r a n s . t y p e ;

pReading2−>p a r e n t a d d r = c a l l R o u t e C o n t r o l . g e t P a r e n t ( ) ; pReading2−>r e a d i n g = m s g r e t r a n s . r e a d i n g ;

pReading2−>o r i g e m a d d r = m s g r e t r a n s . o r i g e m a d d r ; pReading2−>numseq = m s g r e t r a n s . numseq ;

pReading2−>i n t e r c e p t a d d r = m s g r e t r a n s . i n t e r c e p t a d d r ; pReading2−>i n t e r c e p t a n t = m s g r e t r a n s . i n t e r c e p t a n t ; pReading2−>I D c o n e x = m s g r e t r a n s . I D c o n e x ;

c o n t r e t r a n s ++;

No documento Cap´ıtulo 1 Introdu¸ c˜ ao (páginas 118-154)

Documentos relacionados