Saturday, March 18, 2017

Software Systems Architecture - Notes

This month I have picked the book "Software Systems Architecture - Working with StakeHolders with ViewPoints and Perspectives". As I go through the book, I would like to take some notes and keep posting it here. There are two motivations for reviving this blog after long time:
1) Improving writing skills
2) Writing forces clarity of thought and will prevent me from just skimming through this 500 page book.

- The architect works with different people having different set of concerns about the new system. People affected by the system are called 'stakeholders'. They may have conflicting concerns. Success of architecture lies in effectively addressing them.

- Another problem architect faces is about communicating the multifaceted architecture to these stakeholders. A solution that can work is to split the description into 'viewpoints'.

- What a system does is only part of the story, stakeholders's perception is also affected by how the system is implemented.
"The architecture you choose for a system dictates how quickly it runs, how secure it is, how available it is, how easy it is to modify, and many other nonfunctional factors, which we collectively term 'quality properties'." 
 These are also known as 'cross-cutting concerns'. 'Perspective' is similar to viewpoint, but it addresses quality properties.

Software Architecture Concepts:

  Definition: The architecture of a system is the set of fundamental properties of the system in its environment, embodied in its elements, relationships, and the principles of its design and evolution.




Saturday, September 3, 2011

OpenMP with GCC


std::vector < int >  a(N, 1), b(N, 2), c(N, 0);
   
#pragma omp parallel for
for (i=0; i < N; ++i)
    c[i] = a[i] + b[i];

g++ test.cc -fopenmp -o parallel_for

On a dual-core machine, it was up to 80% faster than the normal for loop.





Tuesday, March 1, 2011

How MPLS handles ECMP:

source: http://tools.ietf.org/html/draft-ietf-mpls-ecmp-bcp-01

Current EMCP Practices [as of 2005]

The MPLS label stack and Forwarding Equivalence Classes are defined
in [RFC3031]. The MPLS label stack does not carry a Protocol Identi-
fier. Instead the payload of an MPLS packet is identified by the
Forwarding Equivalence Class (FEC) of the bottom most label.
Thus it
is not possible to know the payload type if one does not know the
label binding for the bottom most label. Since an LSR which is pro-
cessing a label stack need only know the binding for the label(s) it
must process, it is very often the case that LSRs along an LSP are
unable to determine the payload type of the carried contents.


As a means of potentially reducing delay and congestion, IP networks
have taken advantage of multiple paths through a network by splitting
traffic flows across those paths. The general name for this practice
is Equal Cost Multipath or ECMP. In general this is done by hashing
on various fields on the IP or contained headers. In practice,
within a network core, the hashing in based mainly or exclusively on
the IP source and destination addresses.
The reason for splitting
aggregated flows in this manner is to minimize the re-ordering of
packets belonging to individual flows contained within the aggregated
flow. Within this document we use the term IP ECMP for this type of
forwarding algorithm.

In the early days of MPLS, the payload was almost exclusively IP.
Even today the overwhelming majority of carried traffic remains IP.
Providers of MPLS equipment sought to continue this IP ECMP behavior.
As shown above, it is not possible to know whether the payload of an
MPLS packet is IP at every place where IP ECMP needs to be performed.
Thus vendors have taken the liberty of guessing what the payload is.
By inspecting the first nibble beyond the label stack, it can be
inferred that a packet is not IPv4 or IPv6 if the value of the nibble
(where the IP version number would be found) is not 0x4 or 0x6
respectively. Most deployed LSRs will treat a packet whose first
nibble is equal to 0x4 as if the payload were IPv4 for purposes of IP
ECMP.


A consequence of this is that any application which defines a FEC
which does not take measures to prevent the values 0x4 and 0x6 from
occurring in the first nibble of the payload may be subject to IP
ECMP and thus having their flows take multiple paths and arriving
with considerable jitter and possibly out of order. While none of
this is in violation of the basic service offering of IP, it is
detrimental to the performance of various classes of applications.
It also complicates the measurement, monitoring and tracing of those
flows.

New MPLS payload types are emerging such as those specified by the
IETF PWE3 and AVT working groups. These payloads are not IP and, if
specified without constraint might be mistaken for IP.

It must also be noted that LSRs which correctly identify a payload as
not being IP, may still need to load-share this traffic across multi-
ple equal-cost paths. In this case a LABEL ECMP algorithm is
employed, where a hash is computed on all or part(s) of the label
stack. Any reserved label, no matter where it is located in the
stack, may be included in the computation for load balancing. Modi-
fication of the label stack between packets of a single flow could
result in re-ordering that flow. That is, were an explicit null or a
router-alert label to be added to a packet, that packet could take a
different path through the network.


Note that for some applications, being mistaken for IPv4 may not be
detrimental. The trivial case where the payload behind the top label
is a packet belonging to an MPLS IPv4 VPN. Here the real payload is
IP and most (if not all) deployed equipment will locate the end of
the label stack and correctly perform IP ECMP.

A less obvious case is when the packets of a given flow happen to
have constant values in the fields upon which IP ECMP would be per-
formed. For example if an ethernet frame immediately follows the
label and the LSR does not do ECMP on IPv6, then either the first
nibble will be 0x4 or it will be something else. If the nibble is
not 0x4 then no IP ECMP is performed, but Label ECMP may be per-
formed. If it is 0x4, then the constant values of the MAC addresses
overlay the fields that would be occupied by the source and destina-
tion addresses of an IP header.

Monday, September 20, 2010

Vim Recording Example

Problem:

Given a file with exactly two lines for each IP (for a defined set of IPs) as follows:

<router ip="a.b.c.d" id="">
<router ip="p.q.r.s" id="">
a.b.c.d,23
p.q.r.s,24
...
...

Need to fill the xml attribute 'id' with matching value.

Vim Recording to rescue:

1. Go to a.b.c.d
2. Record in register 'c'
qc
3. search for comma
/\<,\>
4. Go to next word.
w
5. Copy the text after comma (which is the value of id) to buffer 'x':
"xy$
6. Step back to comma
b
5. Copy the text before comma to buffer 'z':
"zy0
6. Search for z-buffer-contents in file.
/\
To copy z buffer contents:
Ctrl-R z
7. Search for next instance
n
8. copy the value of id from x register to id=""
/id="
3w
"xp
9. search for next instance. (original instance)
n
10. Next line.
j
11. beginning of line.
0

Apply to 1000 lines:
1000@c

Done.

Tuesday, June 15, 2010

Changing parsed-variable order in boost.spirit

Problem Statement:

You have defined a structure in which you want to save result of a spirit's rule. There is another rule in your grammar which has exactly same data fields as the above rule but in a different order. How do you reuse your structure?


For this example lets use following structure:

struct Date
{
int month;
int day;
int year;
};

Now we convert it into a boost fusion sequence

BOOST_FUSION_ADAPT_STRUCT(
Date,
(int, month)
(int, day)
(int, year)
)

This is US date format.

we define this rule to parse US dates:
date_rule %= int_ >> lit(':') >> int_ >> lit(':') >> int_;

and we put the parsed result in our Date structure:
Date date;
phrase_parse(begin, end, date_rule, space, date);

now how to parse UK format dates? (day:month:year) ?

there are two options;
1) use Date structure to parse and swap the fields around.
2) define a new rule which does the swapping by itself.

here I describe option 2.

uk_date_format = int_ [at_c<1>(_val) = _1]
>> lit (':') >> int_[at_c<0>(_val) = _1]
>> lit (':') >> int_[at_c<2>(_val) = _1];

phrase_parse(begin, end, uk_date_format, space, date);

(at_c is used to access phoenix tuple.)

Tuesday, May 18, 2010

Wednesday, May 12, 2010

building gcc4.5 on linux

1) Download gcc sources:
svn co svn://gcc.gnu.org/svn/gcc/branches/gcc-4_5-branch
2) Download other resources required:
wget ftp://gcc.gnu.org:21/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
wget ftp://gcc.gnu.org:21/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
wget ftp://gcc.gnu.org:21/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.64.tar.gz (might be needed)
3) build gmp, mpfr and mpc:
a) cd gmp-4.3.2
./configure --prefix=/usr/local
make
sudo make install
b) cd mpfr-2.4.2
./configure --prefix=/usr/local
make
sudo make install
c) cd mpc-0.8.1
./configure --prefix=/usr/local
make
sudo make install
NOTE: if it fails with 'relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC'
Make sure that you are using /usr/local/lib/libmpfr.so

4) cd gcc-4_5-branch
a) autoconf (it may ask for upgrading to 2.64)
b) LD_RUN_PATH=/usr/local/lib
export LD_RUN_PATH
LDFLAGS="-L/usr/local/lib -R/usr/local/lib"
export LDFLAGS
c) configure gcc:
./configure --prefix=/usr/local --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++ --disable-dssi --enable-plugin --with-cpu=generic --host=x86_64-redhat-linux --build=x86_64-redhat-linux --with-gmp=/usr/local/ --with-mpfr=/usr/local/ --with-mpc=/usr/local
d) make
e) sudo make install