Wednesday, October 31, 2012

CPP 1 - Program Structure and Compilation

Previous | C++ Home | Next


In order to program in C++ you will need:
  1. Computer.
  2. Linux or Windows Operating System.
  3. C++ compiler.
If you use linux the compiler is already available for you. In case you use windows operating system, you will need to download some IDE with C++ compiler. You can use one for free at: http://www.codeblocks.org/

The best way to learn how to write programs is ... to actually start writing them. Unlike some other, also  cool programming languages, such as  python which is are called 'interpreted' language, C++ is a bit more difficult to start with. Every time we have a problem to solve using C++, we will need to carry out the following steps:
  1. Writing a code in a text editor (or IDE).
  2. Compile it (if there is problem with our syntax, the compiler will tell us about it).
  3. Correct any problems found by the compiler (missing semicolon, brace, etc.).
  4. Run the code to test it.
Later, we may find some problems that the compiler will not find (called them bugs). They are more difficult to find, but in our course we should not have to many problems of this sort.

C++ is very fussy about details (syntax), so I advise that you type each code I present here watching every character (comma, semicolon, lef/right brace etc) as you do so.  

NOTE
Do NOT copy and paste the code ever. You develop your skills by typing the code as well.

NOTE
You probably do not know what compilation is and there will be many things that will baffle you in the beginning. Do not worry about it now. Just take those things for granted.  Explanations to those bits will come later. Now, it is all about repeating the process and having some fun with it From now on, you are the boss.

Here is your initial code structure we will use starting every program (well, sometimes we will add some more stuff, but the below will always be present). 


Pic. 1.1 - C++ Program Structure

Code Structure:


#inlcude <iostream>

using namespace std;

int main() {

return 0;
}


If you have carefuly typed in the code above into your editor or software development kit, and saved it as ex001.cpp, now compile it. If you did well, the compiler will not show any error. If you use linux box you can use the following command (do not type in the '$' sign):


$ g++ -o ex1 ex001.cpp

If you use Microsoft Windows and codeblocks IDE, just open a new project, type the code in and save it. Then click the icon in the menu that has a green arrow similar to the one used on DVDs ;). If you see no errors in the bottom of the page we're good.

Tuesday, October 23, 2012

Lab 204 - OSPFv3 Virtual Link

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Configure OSPFv3 area 45 between R4 and R5 on their point-to-point link. IPv6 addresses should follow the pattern you have used in previous labs. Configure OSPFv3 area 215 between R5 and SW2. Ensure full IPv6 connectivity within the routing domain.

Solution

Task 1
Configure OSPFv3 area 45 between R4 and R5 on their point-to-point link. IPv6 addresses should follow the pattern you have used in previous labs. Configure OSPFv3 area 215 between R5 and SW2. Ensure full IPv6 connectivity within the routing domain.

R4 Config:
!
ipv6 router ospf 1
 router-id 4.4.4.4
 area 45 virtual-link 5.5.5.5
!
interface Serial0/1
 ip address 172.16.45.4 255.255.255.0
 ipv6 address FC00:1:1:45::4/64
 ipv6 ospf 1 area 45
 clock rate 2000000
!

R5 Config:
!
ipv6 unicast-routing
!
ipv6 router ospf 1
 router-id 5.5.5.5
 area 45 virtual-link 4.4.4.4
!
interface Serial0/1
 ip address 172.16.45.5 255.255.255.0
 ipv6 address FC00:1:1:45::5/64
 ipv6 ospf 1 area 45
 clock rate 2000000
!
interface FastEthernet0/1
 speed 100
 full-duplex
 ipv6 address FC00:1:1:D7::5/64
 ipv6 ospf 1 area 215
!

SW2 Config:
!
ipv6 unicast-routing
!
ipv6 router ospf 1
 router-id 10.10.10.10
!
interface Vlan215
 ip address 172.16.215.8 255.255.255.0
 ipv6 address FC00:1:1:D7::8/64
 ipv6 address FC00:1:1:D7::10/64
 ipv6 ospf 1 area 215
!

Verification:

Pic. 2 - SW2's Routing Table.

Pic. 3 - Virtual Link Between R4 and R5.

Lab 203 - OSPFv3 Path Influencing

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Modify previous lab's configuration of OSPFv3 between R3, R4, and R6 as shown in Pic. 2:

Pic. 2



Task 2
Enable OSPFv3 between R4 and R6. Broadcast network should use addresses according to the topology diagram with ::x as their host portion, where 'x' is the router number.

Task 3
Ensure that R3 uses R6 as its primary gateway towards FC00:1:1:2D::/64. In case of R6 being unavailable, R3 is to choose R4 to reach the network in question. Configuration should be done on R3.

Solution

Task 1
Modify previous lab's configuration of OSPFv3 between R3R4, and R6 as shown in Pic. 2.

R3 Config:
!
interface Serial0/1
 encapsulation frame-relay
 ipv6 address FE80::3 link-local
 ipv6 address FC00::3/64
 ipv6 ospf network point-to-multipoint
 ipv6 ospf 1 area 0
 clock rate 2000000
 frame-relay map ipv6 FC00::4 314 broadcast
 frame-relay map ipv6 FC00::6 316 broadcast
 frame-relay map ipv6 FE80::6 316
 frame-relay map ipv6 FE80::4 314
 no frame-relay inverse-arp
!

R4 Config:
!

interface Serial0/0
 encapsulation frame-relay
 ipv6 address FE80::4 link-local
 ipv6 address FC00::4/64
 ipv6 ospf network point-to-multipoint
 ipv6 ospf 1 area 0
 clock rate 2000000
 frame-relay map ipv6 FE80::3 413 broadcast
 frame-relay map ipv6 FC00::3 413
 no frame-relay inverse-arp
!

R6 Config:
!
interface Serial0/0
 encapsulation frame-relay
 ipv6 address FE80::6 link-local
 ipv6 address FC00::6/64
 ipv6 ospf network point-to-multipoint
 ipv6 ospf 1 area 0
 clock rate 2000000
 frame-relay map ipv6 FE80::3 613 broadcast
 frame-relay map ipv6 FC00::3 613
 no frame-relay inverse-arp
!

Task 2
Enable OSPFv3 between R4 and R6. Broadcast network should use addresses according to the topology diagram with ::x as their host portion, where 'x' is the router number.

R4 Config:
!
interface FastEthernet0/0
 speed 100
 full-duplex
 ipv6 address FC00:1:1:2D::4/64
 ipv6 ospf 1 area 0
!

R6 Config:
!
interface FastEthernet0/1
 ip address 172.16.46.6 255.255.255.0
 speed 100
 full-duplex
 ipv6 address FC00:1:1:2D::6/64
 ipv6 ospf 1 area 0
!


Verfication:
Pic. 3 - R4 and R6 OSPFv6 Neighbors.


Task 3
Ensure that R3 uses R6 as its primary gateway towards FC00:1:1:2D::/64. In case of R6 being unavailable, R3 is to choose R4 to reach the network in question. Configuration should be done on R3.

Before path influencing:

Pic. 4.

R3 Config:
!
interface Serial0/1
  ipv6 ospf neighbor FE80::4 cost 65
!

Routing table after the configuration change:

Pic. 5.


Soliloquy





Disclaimer!
This is a personal weblog. The opinions expressed here represent my own and not those of my employer. Also my stupidity is mine and mine alone. Since some post content might be rude, offensive or borderline obnoxious (anything marked with label 'Ranting' is not suitable for people under 18 years old). Since I try to have an open mind you can expect that my opinions may and probably will change in time and I may contradict myself in the future. You may leave some comments but I reserve the right to ignore them completely. 

The technical content of this blog is a product of weekend/sleepless-and-or-hotel night/after-work technical struggle. Despite all efforts, it may be inaccurate and reflects the author's knowledge as of the time of writing the posts. The author of the posts will not assume any liability or responsibility to any person or entity with respect to loss or damages incurred from information contained in this blog. Any resemblance to some other training materials and/or CCIE exam is completely coincidental.. 


C++ Introduction

Maggie, complete the following tasks. Good luck.

Exercise 1
Write a code that displays two lines in the command window and the trailing new line. Compile and run it to test it. The result should be similar to mine presented below; make sure the cursor start at new line).



Extra Credit
  1. What is the structure of the C++ program required to properly compile and run?
  2. What is the statement that displays a text on a screen (text = string)?
  3. What do you need to include in the code to display the string on a screen?
  4. What character do you use to end a statement in C++?
Hint
http://www.cplusplus.com/doc/tutorial/program_structure/

Exercise 2
Write a code that asks a user for two integer numbers. The numbers should be multiplied and result displayed (look at the example below). The program should ask the user if she/he wants to do it again.



Extra Credit
  1. What is the difference between do-loop and do-while-loop?
  2. What third type of loop do you know and in which situation would you prefer to use it rather than while-loop?
  3. What type of variable did you use to store user's answer to the question after showing the result?
  4. What other types of variables are used in C++?
  5. Can you tell the characters used for addition, subtraction, multiplication, division?
Hint
http://www.cplusplus.com/doc/tutorial/variables/

Linux Monologue



10/23/2012
Had to re-install my linux box. I stick to older Ubuntu (11.04) because it is much harder to disable Unity in more recent distributions. In short: Unity on a pad might be okay, but Unity on a computer sucks. 
Big time! 

When it is no longer supported by Canonical, will have to move to some other Debian flavor I think.

Stuff to do after installing a fresh copy:

Playing DVD/Restricted 
(versions: 10.10, 11.04, 11.10 and 12.04)


$ sudo apt-get install libdvdread4
$ sudo /usr/share/doc/libdvdread4/install-css.sh

Reboot might be necessary for the change to take effect.




For programming in Python I would need to create a file .vimrc in the $HOME directory. The content of the file should look like this:

set tabstop=4
set shiftwidth=4
set expandtab
set number

Explanation of some settings:
To insert space characters whenever the tab key is pressed, set the 'expandtab' option:

:set expandtab

With this option set, if you want to enter a real tab character use Ctrl-V key sequence.

To control the number of space characters that will be inserted when the tab key is pressed, set the 'tabstop' option. For example, to insert 4 spaces for a tab, use:

:set tabstop=4

After the 'expandtab' option is set, all the new tab characters entered will be changed to spaces. This will not affect the existing tab characters. To change all the existing tab characters to match the current tab settings, use:

:retab

To change the number of space characters inserted for indentation, use the 'shiftwidth' option:

:set shiftwidth=4

For example, to get the following coding style,

No tabs in the source file.
All tab characters are 4 space characters.
use the following set of options:

:set tabstop=4
:set shiftwidth=4
:set expandtab

Display the numbers which help diagnosing problems with programs, set the following option:

:set number

The best way is to create .vimrc file in your home directory and type in all required options.





I experimented with bitrate and this one produces high quality conversion it seems.

mencoder -forceidx rush.code.flv -ovc xvid -xvidencopts bitrate=1350 -oac mp3lame -o rush.code.avi





This one fits perfectly the Youtube type video conversion

mencoder lab174.ogv -ovc xvid -oac mp3lame -xvidencopts pass=1 -o lab174.avi


Monday, October 22, 2012

Lab 202 - OSPFv3 in NBMA Networks

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Configure manual IPv6 addresses on Frame-Relay connections between R3, R4, and R6. IPv6 global addresses should reflect the topology diagram. Host portion of the address should be ::X. For link-local addresses use: FE80::X. In both cases 'X' is the router's number (3, 4, and 6).

Task 2
Enable OSPFv6 area 0 between the routers mentioned in Task 1 using the default OSPF mode. OSPF router's IDs should be as follows:
  • R3 - 3.3.3.3
  • R4 - 4.4.4.4
  • R6 - 6.6.6.6 
Task 3
Advertise into OSPF the following Loopback addresses:
  • R3 - FC00:A:A:A::3/128
  • R4 - FC00:A:A:A::4/128
  • R6 - FC00:A:A:A::3/128
Solution

Task 1
Configure manual IPv6 addresses on Frame-Relay connections between R3R4, and R6. IPv6 global addresses should reflect the topology diagram. Host portion of the address should be ::X. For link-local addresses use: FE80::X. In both cases 'X' is the router's number (3, 4, and 6).

R3 Config:

!
interface Serial0/1
 encapsulation frame-relay
 ipv6 address FE80::3 link-local
 ipv6 address FC00::3/64
 ipv6 ospf neighbor FE80::6
 ipv6 ospf neighbor FE80::4
 clock rate 2000000
 frame-relay map ipv6 FC00::4 314
 frame-relay map ipv6 FC00::6 316
 frame-relay map ipv6 FE80::6 316
 frame-relay map ipv6 FE80::4 314
 no frame-relay inverse-arp
!


R4 Config:

!
interface Serial0/0
 encapsulation frame-relay
 ipv6 address FE80::4 link-local
 ipv6 address FC00::4/64
 ipv6 ospf priority 0
 clock rate 2000000
 frame-relay map ipv6 FE80::6 413
 frame-relay map ipv6 FE80::3 413
 frame-relay map ipv6 FC00::6 413
 frame-relay map ipv6 FC00::3 413
 no frame-relay inverse-arp
!


R6 Config:

!
interface Serial0/0
 encapsulation frame-relay
 ipv6 address FE80::6 link-local
 ipv6 address FC00::6/64
 ipv6 ospf priority 0
 clock rate 2000000
 frame-relay map ipv6 FE80::4 613
 frame-relay map ipv6 FE80::3 613
 frame-relay map ipv6 FC00::4 613
 frame-relay map ipv6 FC00::3 613
 no frame-relay inverse-arp
!

Task 2
Enable OSPFv6 area 0 between the routers mentioned in Task 1 using the default OSPF mode. OSPF router's IDs should be as follows:
  • R3 - 3.3.3.3
  • R4 - 4.4.4.4
  • R6 - 6.6.6.6 
R3 Config:
!
ipv6 unicast-routing
!
ipv6 router ospf 1
 router-id 3.3.3.3
!
interface Serial0/1
 ipv6 ospf neighbor FE80::6
 ipv6 ospf neighbor FE80::4
 ipv6 ospf 1 area 0


R4 Config:
!
ipv6 unicast-routing
!
ipv6 router ospf 1
 router-id 4.4.4.4
!
interface Serial0/0
 ipv6 ospf 1 area 0
 ipv6 ospf priority 0
!

R6 Config:
!
ipv6 unicast-routing
!
ipv6 router ospf 1
 router-id 6.6.6.6
!
interface Serial0/0
 ipv6 ospf 1 area 0
 ipv6 ospf priority 0
!

Verification:

Pic.2 - R3's OSPFv3 Neighbors.


Task 3
Advertise into OSPF the following Loopback addresses:
  • R3 - FC00:A:A:A::3/128
  • R4 - FC00:A:A:A::4/128
  • R6 - FC00:A:A:A::3/128
R3 Config:
!
interface Loopback0
 ipv6 address FC00:A:A:A::3/128
 ipv6 ospf 1 area 0
!

R4 Config:
!
interface Loopback0
 ipv6 address FC00:A:A:A::4/128
 ipv6 ospf 1 area 0
!

R6 Config:
!
interface Loopback0
 ipv6 address FC00:A:A:A::6/128
 ipv6 ospf 1 area 0
!

Verification:

Pic. 3 - Ping Test.

Lab 201 - EIGRPv6 Unequal Load Balance

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Configure IPv6 addresses between R2 and R3 on their Serial1/0 links. Enable EIGRPv6 AS 1 on these interfaces. Follow the IPv6 addressing scheme used in previous labs.

Task 2
Configure Frame-Relay Connection between R2 and R3 so that EIGRPv6 thinks it is a half the speed of Serial1/0. 

Task 3
Enable unequal cost load balancing between R2 and R3.

Solution

Task 1
Configure IPv6 addresses between R2 and R3 on their Serial1/0 links. Enable EIGRPv6 AS 1 on these interfaces. Follow the IPv6 addressing scheme used in previous labs.

R2 Config:
!
interface Serial1/0
 ipv6 address FC00:1:1:20::2/64
 ipv6 eigrp 1
 serial restart-delay 0
!

R3 Config:
!
interface Serial1/0
 ipv6 address FC00:1:1:20::3/64
 ipv6 eigrp 1
 serial restart-delay 0
!

Task 2
Configure Frame-Relay Connection between R2 and R3 so that EIGRPv6 thinks it is a half the speed of Serial1/0. 

Pic. 2 - Interface Speed Before the Adjustment (both).

R2 Config:
!
interface Serial0/0
 bandwidth 772
!

R3 Config:
!
interface Serial0/0.123
 bandwidth 772
!

Task 3
Enable unequal cost load balancing between R2 and R3.

Check if the second link (Serial0/0.123) is a Feasible Successor.

Pic. 3 - Picking FC00:A:A:A::2/128 for Feasible Successor.

Frame-Relay connection is the Feasible Successor (AD < FD) which is pre-requisite for un-equal load balancing. 

Currently, R3 has only one next-hop address towards FC00:A:A:A::2/128.

Pic. 4 - R3's Path for FC00:A:A:A::2/128.

R2 Config:
!
ipv6 router eigrp 1
 variance 2
 no shutdown
!

R3 Config:
!
ipv6 router eigrp 1
 variance 2
 no shutdown
!

After modifying 'variance':

Pic. 5 - R3's Path for FC00:A:A:A::2/128.

Sunday, October 21, 2012

Lab 200 - EIGRPv6 Authentication

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Configure EIGRPv6 authentication between R2 and SW1. Use password CISCO.

Solution

Task 1
Configure EIGRPv6 authentication between R2 and SW1. Use password CISCO.

R2 Config:
!
key chain EIGRPv6
 key 1
   key-string CISCO
!
interface FastEthernet0/0
 ip address 172.16.27.2 255.255.255.0
 speed 100
 full-duplex
 ipv6 address FC00:1:1:1B::2/64
 ipv6 eigrp 1
 ipv6 authentication mode eigrp 1 md5
 ipv6 authentication key-chain eigrp 1 EIGRPv6
 ipv6 summary-address eigrp 1 ::/0 5
end
!

SW1 Config:
!
key chain EIGRPv6
 key 1
   key-string CISCO
!
interface Vlan27

 ip address 172.16.27.7 255.255.255.0

 ipv6 address FC00:1:1:1B::7/64
 ipv6 eigrp 1
 ipv6 authentication mode eigrp 1 md5
 ipv6 authentication key-chain eigrp 1 EIGRPv6
!

Lab 199 - EIGRPv6 Prefix Summarization

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Configure IPv6 prefix summarization of Loopback0 addresses of R1, R2, and R3. R5 and SW2 should receive the summary prefix. Check IPv6 connectivity towards them from R5.

Solution

Task 1
Configure IPv6 prefix summarization of Loopback0 addresses of R1R2, and R3R5 and SW2 should receive the summary prefix. Check IPv6 connectivity towards them from R5.

R1 Config:
!
interface FastEthernet0/1
 ip address 172.16.215.1 255.255.255.0
 speed 100
 full-duplex
 ipv6 address FC00:1:1:D7::1/64
 ipv6 eigrp 1
 ipv6 summary-address eigrp 1 FC00:A:A:A::/126 5
!

Verification:
Pic. 2 - R5's Summarized Routing Table.

Pic. 3 - R5's Detailed Prefixes.

In Pic. 3 all specific prefixes are available as expected according to the summary route. Prefix FC00:A:A:A::4, that is not summarized, and unknown destinations the default route will be used.

Lab 198 - EIGRPv6 Default Route 2

Prerequisites: CCNP level skills.

Topology

Notice!
IPv6 addresses have changed. Follow the below topology diagram and tasks to accomplish the goals.

Pic1. IPv6 Topology Diagram.

Task 1
Enable EIGRPv6 Autonomous System 1 between R1, R5, and SW2. Use addresses presented in the topology diagram. Host portion should follow our previous labs (here: R1=1, R5=5, SW2=8).

Task 2
Allow R5 and SW2 learn all IPv6 prefixes enabled in the previous labs. Configure R1 as a default gateway for all unknown addresses. Do not use summarization to accomplish the goal. You are allowed to use a static route in R1's configuration. 

Solution


Task 1
Enable EIGRPv6 Autonomous System 1 between R1R5, and SW2. Use addresses presented in the topology diagram. Host portion should follow our previous labs (here: R1=1, R5=5, SW2=8).

R1 Config:
!
interface FastEthernet0/1
 ip address 172.16.215.1 255.255.255.0
 speed 100
 full-duplex
 ipv6 address FC00:1:1:D7::1/64
 ipv6 eigrp 1
!

R5 Config:
!
ipv6 unicast-routing
!
ipv6 router eigrp 1
 no shutdown
!
interface FastEthernet0/1
 ip address 172.16.215.5 255.255.255.0
 speed 100
 full-duplex
 ipv6 address FC00:1:1:D7::5/64
 ipv6 eigrp 1
!

SW2 Config
!
ipv6 unicast-routing
!
ipv6 router eigrp 1
 no shutdown
!
interface Vlan215
 ip address 172.16.215.8 255.255.255.0
 ipv6 address FC00:1:1:D7::8/64
 ipv6 eigrp 1
!

Task 2
Allow R5 and SW2 learn all IPv6 prefixes enabled in the previous labs. Configure R1 as a default gateway for all unknown addresses. Do not use summarization to accomplish the goal. You are allowed to use a static route in R1's configuration.

R1 Config:
!
ipv6 route ::/0 null0
!
ipv6 router eigrp 1
 no shutdown
 redistribute static
!

Verification:
Pic. 2 - Default Route in R5.