Tuesday, June 12, 2012

Caricature: Essays and thesis written in programming languages


Sunday, June 10, 2012

Installing Fuzuli for Windows

Well, it was difficult to shut down our Linux installed machines and start up Windows after a long time interval. Unfortunately, there are many Windows users around the world that want to try out Fuzuli, our new interpreter which is first introduced in Practical Code Solutions blog.

We compiled Fuzuli using GNU C++ compiler and prepared some Linux packages which are ready to download at Google Code page. In order to compile it Windows, we had to use GNU for Windows, namely CYGWIN. Finally, we have a running copy at hand and it is ready to download in page Download Packages. Installing Fuzuli in Windows is such an easy task. Just follow the required steps and start running and testing Fuzuli.

  1. Go to the page http://code.google.com/p/fuzuli/downloads/list and download Fuzuli for Windows.
  2. The current zip file is fuzuli-win_0.1-4.zip but it depends on the current release. It will have a new name in the future but in the same pattern.
  3. Extract the zip file, for example in C:\, so your Fuzuli folder becomes c:\fuzuli-win_0.1-4.

 Okay, by now on, you will have installed Fuzuli! Let's test it using following steps:
  1. Click button. Select run and type "cmd". Press enter. This will open a terminal screen.



  2. Type "cd C:\fuzuli-win_0.1-4" and type enter. This will get you in the Fuzuli folder. 





  3. Type "fuzuli" and type enter. 
 You would see an output like this:


Fuzuli build Jun  9 2012 12:59:18
usage:
 fuzuli source
 fuzuli --repl



If you see the output shown above, you probably installed Fuzuli successfuly. Lets try a program. There is fzl file shipped with Fuzuli with name fibonacci.fzl. This file is a text file and can be edited a text editor like Notepad or Notepad++. You can run it by typing



fuzuli fibonacci.fzl


and if there is not any problem, the output should be like this:

PASSED!
PASSED!
PASSED!
PASSED!
PASSED!


The output shown above proofs that Fuzuli is ready. You can create your own fzl files and run them in a similar way.

Ok. Let write a world classic, Hello World!. Open your favorite text editor, it is Notepad++ if I work with Windows.

 
Now save it with name "hello.fzl" in some folder. Do not forget where you saved the file. I saved my hello.fzl in directory D:\myfuzuli so it is D:\myfuzuli\hello.fzl







 Okay, see you later in next article!

 

 

 



Saturday, June 9, 2012

How to Use JQuery UI Progress Bar

Hi! As you know, we wrote something about JQuery before. We'd talked about where and how to use it. 


In this article, we're going to learn using progress bar we all know. For using it, have to include the library about this. Like i said, this article is about showing load progress using JQuery UI.


I guess that we all need to load progress while our pages was loading on. All of expert of software think about that is the best way ever. For that reason, this is indispensable for us :)


Well, we'd talked about the libraries. If you learn how to use those, you can visit Jquery web site


Your Html Page should be like:

<div id="progressbar"></div>

When the script stars and loads, progress bar will work on the div layer which's id is progressbar.

This is my jquery document:

$(document).ready(function() {
 var count = 0;
 setInterval(function() {
  count = count + 0.5;
  $('#progressbar').progressbar({
   value : count         
  });
 }, 10);
});

As you see, setInterval function is counting our count and then load the page. I used to 0.5 value. If you want to load faster or slower, can change the 0.5 value, namely value of count.

If you want to see how the demo works, you can visit this page.

Just remember that is an open source project and if you see the code, you can see the code, if you want to get the code, you can get to code also. And libraries we used on the script are here.

We'll see you guys next article!

Friday, June 8, 2012

A Basic QT LCD Number Component Example

In this small example, we demonstrate how to use Qt's LCD Number component with consequent images and codes.

Since Qt is known to be a good GUI library, it has got a collection of classes for general purpose programming on networking, databases and other things.

In our simple example, we have one lcd number component and two buttons for increasing and decreasing the value on it. Events are handling using slots and signals as usual in Qt. First, follow these images.


















The C++ code for main.cpp, mainwindow.cpp and mainwindow.h is shown below:


main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    
    return a.exec();
}


mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->connect(this->ui->pushButton, SIGNAL(clicked()), this,SLOT(button_Plus_click()));
    this->connect(this->ui->pushButton_2, SIGNAL(clicked()), this,SLOT(button_Minus_click()));
    this->counter=10;
    this->ui->lcdNumber->display(counter);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::button_Minus_click(){
    counter--;
    this->ui->lcdNumber->display(counter);
}

void MainWindow::button_Plus_click(){
    counter++;
    this->ui->lcdNumber->display(counter);
}



mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    
private:
    Ui::MainWindow *ui;
    int counter;

private slots:
    void button_Plus_click();
    void button_Minus_click();
};

#endif // MAINWINDOW_H



Good luck!

Monday, June 4, 2012

Using dynagen & dynamips for multible cisco router simulation


dynage dynamips cisco linux console terminal network lab simulation


       If you want to simulate a Cisco router, you can use dynamips but if you want to create a network topology you have to use both of dynagen and dynamips. This blog post is about about creating a sample network topology, connecting routers to each other and testing all nodes in the topology.


       I'm using Ubuntu 12.04 to show an example now. First, we have to install dynagen (and dynamips) on Ubuntu 12.04. Actually we will also need dynamips but dynamips is a dependance of dynamips. So if we install dynagen, dynamips will be installed with dynagen.



ismail@ismail-ThinkPad-T410:~$ sudo apt-get install dynagen 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  dynamips python-configobj
The following NEW packages will be installed:
  dynagen dynamips python-configobj
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,070 kB/1,418 kB of archives.
After this operation, 4,263 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://tr.archive.ubuntu.com/ubuntu/ precise/main python-configobj all 4.7.2+ds-3build1 [233 kB]
Get:2 http://tr.archive.ubuntu.com/ubuntu/ precise/multiverse dynagen all 0.11.0-6 [836 kB]
Fetched 1,070 kB in 0s (1,495 kB/s)
Selecting previously unselected package dynamips.
(Reading database ... 206573 files and directories currently installed.)
Unpacking dynamips (from .../dynamips_0.2.7-0.2.8RC2-5ubuntu1_amd64.deb) ...
Selecting previously unselected package python-configobj.
Unpacking python-configobj (from .../python-configobj_4.7.2+ds-3build1_all.deb) ...
Selecting previously unselected package dynagen.
Unpacking dynagen (from .../dynagen_0.11.0-6_all.deb) ...
Processing triggers for man-db ...
Processing triggers for doc-base ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Setting up dynamips (0.2.7-0.2.8RC2-5ubuntu1) ...
Setting up python-configobj (4.7.2+ds-3build1) ...
Setting up dynagen (0.11.0-6) ...
Processing triggers for python-support ...
ismail@ismail-ThinkPad-T410:~$ 

Let's start to work with sample network topology;



       There are only 3 routers on our sample network topology. Only one dynamips instance should be enough.

1-) Start dynamips instance


ismail@ismail-ThinkPad-T410:~$ dynamips -H 7100 &
[1] 16919
ismail@ismail-ThinkPad-T410:~$ Cisco Router Simulation Platform (version 0.2.8-RC2-amd64)
Copyright (c) 2005-2007 Christophe Fillot.
Build date: Jan 18 2011 19:25:29

Hypervisor TCP control server started (port 7100).

ismail@ismail-ThinkPad-T410:~$ ps -ef | grep dynamips
ismail   16919  8265  6 17:59 pts/2    00:00:00 dynamips -H 7100
ismail   16934  8265  0 17:59 pts/2    00:00:00 grep --color=auto dynamips
ismail@ismail-ThinkPad-T410:~$ 

       We are starting dynamips service with "dynamips -H 7100 &" and checking it with "ps -ef | grep dynamips" command.

2-) Create a dynagen configuration file


# [START INSTANCE1]

[localhost:7100]
  udp=10000
  workingdir = /tmp/working

[[3725]]
  image = /tmp/c3725-adventerprisek9-mz.124-15.T13.bin
  ram = 128
#  idlepc = ?? We will talk about it later.
  ghostios = true
  sparsemem = true
  idlemax = 100
  disk0=128

 [[Router R1]]
  model = 3725
  console = 2001
  autostart = false
#  F0/0 =
  S0/0 = R2 S0/0

 [[Router R2]]
  model = 3725
  console = 2002
  autostart = false
#  F0/0 =
  S0/0 = R1 S0/0
  S0/1 = R3 S0/0

 [[Router R3]]
  model = 3725
  console = 2003
  autostart = false
  S0/0 = R2 S0/1
# F0/0 =

# [FINISH INSTANCE1] 

       First stage is about connecting to an existing dynamips service. Dynamips will create some files when it is loading a topology. This files will be created in  the "workingdir" directory.

       Second stage is about creating a Cisco Router model. We have to define a Cisco ios file path and some hardware specifications in this stage.

       The last stages are about defining our virtual routers. If we create more than one models, we can select different models for earch virtual router. The "console" key defines the port number. We will use this port numbers to connect to console of router. Autostart key defines either manual or auto router booting while starting to dynagen process. Finally we will define  connections between virtual routers.

       I created a "working" directory under /tmp and the dynagen configuration file before starting the dynagen as shown below:

ismail@ismail-ThinkPad-T410:~$ vim /tmp/sample1.net
{write dynagen configuration file content as above INSTANCE1}
ismail@ismail-ThinkPad-T410:~$ 
ismail@ismail-ThinkPad-T410:~$ dynagen /tmp/sample1.net 
Reading configuration file...

Shutdown in progress...
Shutdown completed.
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'ghost-c3725-adventerprisek9-mz.124-15.T13.bin-localhost.ghost' (id 3):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF entry point: 0x80008000

C3725 'ghost-c3725-adventerprisek9-mz.124-15.T13.bin-localhost.ghost': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.

C3725 'ghost-c3725-adventerprisek9-mz.124-15.T13.bin-localhost.ghost': stopping simulation.
Network successfully loaded

Dynagen management console for Dynamips and Pemuwrapper 0.11.0
Copyright (c) 2005-2007 Greg Anuzelli, contributions Pavel Skovajsa

=> list
Name       Type       State      Server          Console   
R1         3725       stopped    localhost:7100  2001      
R2         3725       stopped    localhost:7100  2002      
R3         3725       stopped    localhost:7100  2003      
=> 
=> ?

Documented commands (type help <topic>):
========================================
capture  confreg  cpuinfo  export  hist    list  py      save   show   suspend
clear    console  end      filter  idlepc  no    reload  send   start  telnet 
conf     copy     exit     help    import  push  resume  shell  stop   ver    

=> 
=> start R1
Warning: Starting R1 with no idle-pc value
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
C3725 instance 'R1' (id 0):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF loading skipped, using a ghost RAM file.
ELF entry point: 0x80008000

C3725 'R1': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-VM 'R1' started
=> 
=> start R2
Warning: Starting R2 with no idle-pc value
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'R2' (id 1):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF loading skipped, using a ghost RAM file.
ELF entry point: 0x80008000

C3725 'R2': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-VM 'R2' started
=> start R3
Warning: Starting R3 with no idle-pc value
CPU0: carved JIT exec zone of 64 Mb into 2048 pages of 32 Kb.
NVRAM is empty, setting config register to 0x2142
C3725 instance 'R3' (id 2):
  VM Status  : 0
  RAM size   : 128 Mb
  NVRAM size : 128 Kb
  IOS image  : /tmp/c3725-adventerprisek9-mz.124-15.T13.bin

Loading ELF file '/tmp/c3725-adventerprisek9-mz.124-15.T13.bin'...
ELF loading skipped, using a ghost RAM file.
ELF entry point: 0x80008000

C3725 'R3': starting simulation (CPU0 PC=0xffffffffbfc00000), JIT enabled.
100-VM 'R3' started
=> 

Open another terminal and execute this command:

ismail@ismail-ThinkPad-T410:~$ telnet localhost 2001
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connected to Dynamips VM "R1" (ID 0, type c3725) - Console port

when press enter will appear this;

% Please answer 'yes' or 'no'.
Would you like to enter the initial configuration dialog? [yes/no]: 

press Ctrl+c and enter and enter again:

Press RETURN to get started!


*Mar  1 00:00:03.843: %LINEPROTO-5-UPDOWN: Line protocol on Interface VoIP-Null0, changed state to up
*Mar  1 00:00:03.847: %LINEPROTO-5-UPDOWN: Line protocol on Interface IPv6-mpls, changed state to up
*Mar  1 00:00:03.927: %LINK-3-UPDOWN: Interface Serial0/0, changed state to up
*Mar  1 00:00:03.935: %LINK-3-UPDOWN: Interface Serial0/1, changed state to up
*Mar  1 00:00:04.927: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
*Mar  1 00:00:04.935: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1, changed state to up
*Mar  1 00:00:32.927: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1, changed state to down
*Mar  1 00:01:26.839: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to down
*Mar  1 00:01:32.875: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
*Mar  1 00:01:39.015: %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
*Mar  1 00:0
Router>1:39.075: %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to administratively down
*Mar  1 00:01:40.115: %SYS-5-RESTART: System restarted --
Cisco IOS Software, 3700 Software (C3725-ADVENTERPRISEK9-M), Version 12.4(15)T13, RELEASE SOFTWARE (fc3)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Wed 07-Apr-10 12:44 by prod_rel_team
*Mar  1 00:01:40.123: %SNMP-5-COLDSTART: SNMP agent on host Router is undergoing a cold start
*Mar  1 00:01:40.147: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
*Mar  1 00:01:40.147: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to down
*Mar  1 00:01:40.159: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is OFF
*Mar  1 00:01:40.159: %CRYPTO-6-GDOI_ON_OFF: GDOI is OFF
*Mar  1 00:01:40.951: %LINK-5-CHANGED: Interface Serial0/0, changed state to administratively down
*Mar  1 00:01:40.951: %LINK-5-CHANGED: Interface Serial0/1, changed state to administratively down
*Mar  1 00:01:41.951: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to down
*Mar  1 00:01:43.839: %IP-5-WEBINST_KILL: Terminating DNS process
Router>

        So you can get console for other virtual routers with "telnet localhost 2002", "telnet localhost 2003" and "telnet localhost 2004" commands.   

        I'm preparing more samples for multiple instances, physical ethernet connectivity and switch simulation with dynagen&dynamips.