Monday, June 20, 2011

C Programming Tips and Tricks – Part1:

Signed/Unsigned types:

• Use unsigned types for bit field manipulation and binary masks. For others, use signed types.
• Use casts in expression to avoid compiler interpretation to choose results.

Malloc(strlen(str)) => Wrong (because, need to add 1 byte for null termination character)
Malloc(strlen(str)+1) => Right

Switch:
In switch statement, each case should be labeled by integer-valued constants.

Static:
• For variables => it retains its value between calls; scope is limited to inside function.
• For functions => visible in only this file.

Extern:
• For variables => defined it elsewhere.
• For functions => Global scope(and is redundant)

Declarations and definitions:
Extern int i => it is the declaration (doesn’t reserve space in memory)
Int i =10 => it is the declaration and definition (Creates type and name of the object and reserve space)

Typedef:
Typedef int integer;
Unsigned integer I; // illegal

Process Address Space:

Unmapped region => For null pointer references.


Object file:
• It contains Data segment, Text segment and details of the size required for BSS segment.

Dangling pointer -> doesn’t reference anything. (Generally occurs, when returning address of a local auto variable from function, as the variable no longer exists after function exited)


Memory Issues:
Memory Corruption:
Freeing or overwriting memory that is still in use.

Memory Leak:
Not freeing memory that is not in use.


Declaration of Structures and Unions:
struct/union optional-tag
{
type1 var1;
type2 var2;
} optional_variable_definitions;

→ For Unions, all the members have an offset zero.



Wednesday, June 8, 2011

Fibre Channel Topologies

Fibre Channel Topologies:




Point-to-point:

     • Simplest Topology
     • Consists of only two fibre channel devices connected directly together.
     • Transmission medium is dedicated (Not shared)
     • Providing guaranteed bandwidth, guaranteed latency and in-order frame delivery.

Arbitrated Loop:
     • Cost effective way of connecting 127 ports in a single network without the need of fabric switch.
     • Media is shared among the devices; Limiting each device’s access.
     • When a port needs to access the loop, it must first arbitrate to access the loop. Once a port wins arbitration, it opens a loop circuit with another port. This creates a dynamic point to point connection between the two ports allowing frame transmission to begin.
     • As long as loop circuit is opened, two ports have sole use of the loop. All other ports are acting as repeaters.
     • When the two ports finish their frame transmission, loop circuit is closed and available for other ports to use.

Switched Fabric:
     • Used to connect many (2 power 24) devices in a cross point switched configuration.
     • Many devices can communicate at the same time; Media is not shared; but it is costlier.

Note: Images from Wikipedia.

Fibre Channel Node Port

Fibre Channel Node Port:

Each node has one or more node ports. Node port is a hardware function used for sending and Receiving information via the Fibre Channel Interface.

Each node port has two unique ID’s.
     1. Port_Name
     2. N_Port_ID

Port_name => Unique 64 bit identifier assigned to the port at the time of manufacturing.
                     Used for Management purposes or when port identification is required.

N_Port_ID => Unique 24 bit identifier assigned at the time of initialization of node port and its attached topology.
                   Since it is 24 bit, the maximum size of Fibre Channel Network is 2^24 ports.
                   Used for Routing the information from sending port to receiving port and also used by receiving port to examine, whether the information delivered to correct port or not.
                   N_Port_ID may change, when the configuration is changed. (Because of this, Port_name should be used for identification of port)

Port is further identified based on the topology it supports. For example, to support arbitrated loop topology, the node port should capable of performing loop specific protocols. This kind of node port is called NL_Port.

Each port has separate Transmit and Receive function.
Port Transmit Function:
Port transmit function contains an encoder that transforms binary data into the format suitable for serial transmission by embedding clock information and frequency distribution.
After encoding, information is serialized and transmitted one bit at a time.

Port Receive Function:
Port receive function receives the serial data, recovers clock information from data stream, deserialize the received data, and decodes deserialized information.