06 January 2011

Tetrios - tetris for Cisco routers

IMPORTANT NOTE: Please, do not play Tetrios on production routers. It is possible that router will stop responding in case of incompatible IOS release. Also I assume that if you want to play Tetrios your Tcl skills are sufficient to fix some minor bugs without assistance.

Tetrios is a text based tetris with Tcl code adopted for Cisco IOS. Actually, it is side effect of learning Tcl on New Year holidays. It is very simple, especially if you are able to imagine tetris game like a string. =)

Tetrios code strictly follows 'everything is a string' concept. Another goal was to keep it readable for learning and future modification. I do not pretend that it is optimal. I don't even know tetris algorithm. It is just a result of few days of coding and testing ideas and reading Tcl man. This code was born in my head from the beginning to the end. Hope, it's not bad for a network engineer.

I want to thank Ivan Pepelnjak. His blog is a great source of IOS Tcl tricks. Actually, the first problem with tetris for Cisco routers was that IOS read calls always block for console or vty lines. That's the reason why you can't play Tetrios directly from IOS console and have to use network connection. Also, event loop works very unusual for Cisco IOS, even if we consider all restrictions mentioned on CCO.

Here is a small instruction for Tetrios players:
1) use 'exec-timeout 0' command for those lines, that'll be used by Tcl interpreter
2) adjust delay variable to reduce or increase tetrominoes falling speed; depending on IOS release add or remove 'update' after 'fileevent' in TSERV procedure
3) copy Tetrios code to router flash or some network location as tetrios.tcl
4) enter 'tclsh [tetrios location]/tetrios.tcl' command
5) connect to Tetrios server TCP port (1111 by default):
It is possible that I'll implement a subset of telnet server functionality in future. But currently you have to use raw mode.
6) Enjoy! =)
7) Use 'Ctrl+C' to stop the script. Problems with script termination can arise in some IOS releases. Try to add/remove 'update' after 'fileevent' or use another release.

One of Tetrios cool features is the possibility to log the whole game to a text file from Putty. =)

P.S.: Tetrios is very slow on GNS. It's a little bit faster on real routers. Also, Tetrios works perfectly with ActiveTcl.
P.P.S.: Code still contains some bugs (some problems with boundary check while rotating or shifting tetromino). If you'll play carefully, you should never find them out. May be I'll fix them later. But if you've found a bug with a solution - please post it in comments.

Supported IOS releases (updated):
+ 12.4(15)T8 - version 1.1 tested, works perfectly
+ 15.0(1)M - version 1.1 tested, works perfectly
+ 12.4(24)T - use version 1.0, or remove 'update' after fileevent (looks like a bug)

IOS releases not supported currently:
- 12.4(15)T7 - version 1.1 works, but problems with script termination arise

The code is here temporarily:
Tetrios code on ieoc.com
Tetrios version 1.1 code ('update' after 'fileevent', minor rotation bug fixed)
I hope, it's not a significant fault to use ineoc.com as a storage for a small text file.

And here is a screenshot:

8 comments:

  1. Very nice, there is actually some good points on this blog some of my readers may find this useful, I must send a link, many thanks...
    more info:- Cisco Router Support

    ReplyDelete
  2. Wow, really very useful information. You have posts on protocols. I love to learn more on protocols. thanks for sharing the useful information.....visit more info Cisco Router Support also Call +1-800-231-4635 (Toll Free) .

    ReplyDelete
  3. This is really informative blog! Belkin is one of the most trustable routers in the UK. Belkin Router provides best internet service by their latest features.

    ReplyDelete
  4. Your post is very helpful to get some effective tips to reduce weight properly. You have shared various nice photos of the same. I would like to thank you for sharing these tips. Surely I will try this at home. Keep updating more simple tips like this. best router for verizon fios

    ReplyDelete
  5. Upgrade your network from a slow speed to a fast speed. The Linksys wifi router is a combination of high performance and stability. You can set up your Linksys extender by making use of http extender linksys com You are liable to enjoy advanced wifi features after your setup is done.
    linksys setup wifi extender

    ReplyDelete