\documentclass{ictlab} %\documentclass[solutions]{ictlab} \RCS $Revision: 1.6 $ \usepackage{verbatim,key,alltt,amstext,answer2} \usepackage[hang,bf,nooneline]{caption2} \usepackage[pdfpagemode=None,pdfauthor={Nick Urbanik}]{hyperref} \newcommand*{\labTitle}{Revision Exercises with Perl, routing, switching and LDAP} \renewcommand*{\floatpagefraction}{0.75} % default is .5, to increase % density. \renewcommand*{\bottomfraction}{0.6} % default is 0.3 \renewcommand*{\topfraction}{0.85} % default is 0.7 \renewcommand*{\textfraction}{0.1} % default is 0.2 \providecommand*{\IP}{\acro{IP}\xspace} \providecommand*{\PDU}{\acro{PDU}\xspace} \providecommand*{\IETF}{\acro{IETF}\xspace} \providecommand*{\MAC}{\acro{MAC}\xspace} \begin{document} %% \section{Background} %% \label{sec:background} %% \subsection{Perl} %% \label{sec:perl} %% Refer to the summary of Perl, from the subject web site. I will not %% repeat that here. %% \subsection{Routing} %% \label{sec:routing} %% \begin{itemize*} %% \item %% \end{itemize*} %% \section{Questions} %% \label{sec:questions} \section{Perl} \label{sec:perl} \begin{enumerate} \item Write a regular expression to match two or more ``\texttt{x}''s followed by one or more ``\texttt{y}''s followed by any number of ``\texttt{z}''s. \item[\textbf{Solution:}] All three of these are correct: \begin{verbatim} /xx+y+z*/ /xxx*yy*z*/ /x{2,}y{1,}z{0,}/ \end{verbatim} \item Write a regular expression to match any number of backslashes ``\bs'' followed by any number of asterisks ``\texttt{*}''. Note that ``any number'' might be zero. \item[\textbf{Solution:}] \begin{verbatim} /\\*\**/ \end{verbatim} \begin{figure}[htb] \begin{verbatim} MSRP6604R1 Student Progression Rank Details Page 1 of 4 Academic Year : 2002/03 Course Board Control No. APS1238 Progression Course : 95551/2 in HW 95570/2 in LW 95573/2 in LW 95731/2 in LW Code Student No. Name Attained Loc Course/YearClass 95551/2 987654321 WAN Siu Ming (970) 41.0 TY 41230/1G 95551/2 976543210 FUNG Siu Ming (618) 42.1 TY 41456/2B 95551/2 965432109 YUET Siu Ming (639) 43.2 TY 41789/3B 95551/2 954321098 WONG Siu Ming, Joe (571) 44.3 TY 41012/1G 95551/2 943210987 KLIE Siu Ming (486) 45.4 TY 41345/2G 95551/2 932109876 WANG Siu Hing (370) 46.5 TY 41678/3G 95551/2 921098765 WONG Siu Ming (436) 47.6 TY 41901/1G 95551/2 910987654 FONG Siu Ming (359) TY 41234/3G 95570/2 909876543 HO Siu Ming (133) 49.8 TY 41567/2B \end{verbatim} \caption{A text file containing data} \label{fig:data} \end{figure} \item Figure~\vref{fig:data} shows a text file containing data. Write a Perl program to print all student numbers. \item[\textbf{Solution:}] \begin{verbatim} while ( <> ) { print "$1\n" if /(\d{9})/; } \end{verbatim}%$ \item Write a perl program to print the course, year and class, each in a separate column, separated by a tab character. \item[\textbf{Solution:}] \begin{verbatim} while ( <> ) { print "$1\t$2\t$3\n" if /\s(\d{5})\/(\d)([a-zA-Z])/; } \end{verbatim}%$ \item Write a perl program to generate a password for each student according to the following algorithm: \begin{itemize} \item Take the student's name (but without the number in brackets); \item Remove all spaces and non-alphabetical characters from the name; \item Use the first eight characters left, append them to the last four digits of the student number. \end{itemize} Your program should print: \begin{itemize} \item the student number; \item the full name of the student; \item the student's generated password \end{itemize} all separated by a single tab character. There should be one line of output per student. \item[\textbf{Solution:}] Here is one of many possible solutions. Here I have tried to be clear rather than very concise. \begin{verbatim} #! /usr/bin/perl -w use strict; while ( <> ) { if ( /(\d{9})\s+(\S.*)\s\(/ ) { my ( $student_id, $name ) = ( $1, $2 ); $student_id =~ /(\d{4})$/; my $pw_first = $1; my $pw_second = $name; $pw_second =~ s/[^a-zA-Z]//g; $pw_second =~ /^(.{8})/; $pw_second = $1; my $passwd = "$pw_first$pw_second"; print "$student_id\t$name\t$passwd\n"; } } \end{verbatim}%\) \end{enumerate} Now some people were confused by the pattern match binding operator, \texttt{=}$\sim$, and by the substitute operator, \texttt{s/../../}. Here is a little program that gives some examples of both: \begin{verbatim} #! /usr/bin/perl -w use strict; # Normally a match is made against $_. # If you want to match against another string, use the binding # operator, =~ # Here are some examples: my $string = 'abc'; $string =~ /.(.)./; my $what_is_this = $1; # Notice that no change happened in $string: print "\$string=$string, \$what_is_this=$what_is_this\n"; # see what the substitution operator does: $string =~ s/b/B/; print "\$string=$string\n"; # with no g modifier: $string =~ s/./Z/; print "\$string=$string\n"; # Now see what adding the g modifier does: $string =~ s/./X/g; print "\$string=$string\n"; # $ ./show-match # $string=abc, $what_is_this=b # $string=aBc # $string=ZBc # $string=XXX \end{verbatim} \section{Routing and Switching} \label{sec:routing-and-switching} \begin{enumerate} \item Before a set of candidate network routes can be aggregated, they must be in the \underline{\mbox{\hspace*{30mm}}}, and the routes in binary format must have the \underline{\mbox{\hspace*{30mm}}}. \item[\textbf{Solution:}] Before a set of candidate network routes can be aggregated, they must be in the \underline{same network}, and the routes in binary format must have the \underline{same prefix}. \begin{figure}[htb] \centering% \includegraphics[width=0.8\linewidth]{routing-question-1} \caption{A network with five routers and ten subnets.} \label{fig:routing-question-1} \end{figure} \item Figure~\vref{fig:routing-question-1} shows a network with 5 routers and 10 subnets. You may select \IP addresses from the block of addresses 172.12.0.0/19. You must leave at least one quarter of these addresses available for other purposes. The requirements are that each of subnets 1, 2,\ldots, 8 must support up to 130 computers, while subnets 9 and 10 must each support up to 600 computers. \begin{enumerate} \item Allocate a suitable block of addresses to each of the ten subnets that will allow maximum route aggregation. \item[\textbf{Solution:}] General strategy: determine the lower and upper limits on each subnet. The minimum size of each of the first 8 subnets is 256, i.e., a /24 subnet, as $2^8$ is the lowest power of 2 that contains 130. Let us allocate the lowest 8 /24 blocks: \begin{tabular}[t]{@{}ll@{}} \toprule% \emph{subnet} & \emph{network} \\ \midrule% subnet 1 & 172.12.0.0/24 \\ subnet 2 & 172.12.1.0/24 \\ subnet 3 & 172.12.2.0/24 \\ subnet 4 & 172.12.3.0/24 \\ subnet 5 & 172.12.4.0/24 \\ subnet 6 & 172.12.5.0/24 \\ subnet 7 & 172.12.6.0/24 \\ subnet 8 & 172.12.7.0/24 \\ \bottomrule \end{tabular} The minimum size of subnets 9 and 10 is $2^{10} = 1024$, since $2^{\lceil \log_2 600 \rceil} = 2^{10}$, giving a subnet size of /22. Let us allocate the next lowest 2 /22 blocks: \begin{tabular}[t]{@{}ll@{}} \toprule% \emph{subnet} & \emph{network} \\ \midrule% subnet 9 & 172.12.8.0/22 \\ subnet 10 & 172.12.12.0/22 \\ \bottomrule \end{tabular} This would use only half of the available addresses. \item \label{que:no-summarisation}Given your selection in the previous part, with \emph{no} route summarisation active on the routers, list the routes that would be advertised by router A at X, by router B at W, by router C at V, by router D at Y, and by router E at Z\@. \item[\textbf{Solution:}] \emph{Without} route summarisation, router A will advertise one route for each of its five subnets: \begin{tabular}[t]{@{}l@{}} 172.12.0.0/24 \\ 172.12.1.0/24 \\ 172.12.2.0/24 \\ 172.12.3.0/24 \\ 172.12.4.0/24 \end{tabular} and router B will advertise one route for each of \emph{its} three subnets: \begin{tabular}[t]{@{}l@{}} 172.12.5.0/24 \\ 172.12.6.0/24 \\ 172.12.7.0/24 \end{tabular} Router C will advertise one route for each of its two subnets: \begin{tabular}[t]{@{}l@{}} 172.12.8.0/22 \\ 172.12.12.0/22 \end{tabular} Router D will advertise one route for each of the eight subnets behind routers A and B: \begin{tabular}[t]{@{}l@{}} 172.12.0.0/24 \\ 172.12.1.0/24 \\ 172.12.2.0/24 \\ 172.12.3.0/24 \\ 172.12.4.0/24 \\ 172.12.5.0/24 \\ 172.12.6.0/24 \\ 172.12.7.0/24 \end{tabular} Finally router E will advertise one route for each of the ten subnets behind routers A, B and C: \begin{tabular}[t]{@{}l@{}} 172.12.0.0/24 \\ 172.12.1.0/24 \\ 172.12.2.0/24 \\ 172.12.3.0/24 \\ 172.12.4.0/24 \\ 172.12.5.0/24 \\ 172.12.6.0/24 \\ 172.12.7.0/24 \\ 172.12.8.0/22 \\ 172.12.12.0/22 \end{tabular} \item What would be a necessary requirement for the routers to support route aggregation? \item[\textbf{Solution:}] The routers should be running a classless routing protocol, such as \OSPF or \RIP{}2. \item Repeat part~\ref{que:no-summarisation}, but for the case where the routers all support route summarisation. \item[\textbf{Solution:}] For router~A, the first four routes will be aggregated (summarised), so there will be two routes advertised: \begin{tabular}[t]{@{}l@{}} 172.12.0.0/22 \\ 172.12.4.0/24 \end{tabular} Router B will summarise the last two routes: \begin{tabular}[t]{@{}l@{}} 172.12.5.0/24 \\ 172.12.6.0/23 \end{tabular} Router C will summarise both routes into one: \begin{tabular}[t]{@{}l@{}} 172.12.8.0/21 \end{tabular} Router D will summarise the two routes from router A and the two routes from router B into one route: \begin{tabular}[t]{@{}l@{}} 172.12.0.0/21 \end{tabular} Router E will aggregate the route from router C with the route from router D into one single route: \begin{tabular}[t]{@{}l@{}} 172.12.0.0/20 \end{tabular} Note that here I have ignored the routing to any \IP addresses used on the serial links on the routers. \end{enumerate} %% \item Distinguish between a \emph{broadcast domain} and a %% \emph{collision domain}. %% \item For each of the following, list at least two network devices %% that can separate a single network into: %% \begin{enumerate} %% \item two collision domains %% \item two broadcast domains %% \end{enumerate} \item When using portable notebook computers that should remain on one subnet, what type of \VLAN should be employed? Are there any difficulties in supporting such a \VLAN arrangement? \item[\textbf{Solution:}] They should use a dynamic \VLAN configuration. No matter what data port the notebook is plugged into, it will belong to one particular \VLAN, and hence, in one subnet. The main drawback of this system is maintaining the database of \MAC address --- \VLAN mappings that must be stored in the switches that support this dynamic \VLAN. %% \item List two advantages of using switches in a large network, and %% one important limitation. \begin{figure}[htb] \centering% \includegraphics[width=0.3\linewidth]{switches-q1} \caption{Two switches, each with five ports.} \label{fig:switches-q1} \end{figure} \item Two switches each have five ports, as shown in figure~\vref{fig:switches-q1}. Both switches are to support three \VLAN{}s, \VLAN{}1, \VLAN{}2 and \VLAN{}3. Computers will be connected to each of these three \VLAN{}s on each of the two switches. \begin{enumerate} \item Each \VLAN is to support a separate subnet. How would you connect the switches so that computers on each \VLAN can communicate with each other? Support your answer with a diagram showing the connection of the switches. Label the \VLAN{}s. Indicate whether each port is a trunk port or an access port. \item[\textbf{Solution:}] See figure~\vref{fig:switches-q1-answer}. \begin{figure}[htb] \centering% \includegraphics[width=0.5\linewidth]{switches-q1-answer} \caption{Two switches, each with five ports connected with a router. The trunk ports on the right are connected together to connect the \VLAN{}s on the two switches together. Each \VLAN is a separate subnet. The router connects these subnets together.} \label{fig:switches-q1-answer} \end{figure} \item One additional port is added to each switch. Now two users with portable computers, one belonging to \VLAN{}2 and the other belonging to \VLAN{}3 want to be able to plug into the newly added port on either switch and remain in their respective \VLAN without any manual configuration. How should you configure the new ports in each switch to facilitate this? \item[\textbf{Solution:}] We would configure them as dynamic \VLAN{}s, and add one notebook's \MAC address to dynamic \VLAN{}2, the other to dynamic \VLAN{}3. If notebook-1 has \MAC address \MAC-1, and notebook-2 has \MAC address \MAC-2, and we want notebook-1 on \VLAN{}2, and notebook-2 on \VLAN{}3, then we must enter the following data into the switch's dynamic \VLAN configuration: \begin{tabular}[t]{@{}cc@{}} \toprule% \MAC address & Which \VLAN \\ \midrule% \MAC-1 & \VLAN{}2 \\ \MAC-2 & \VLAN{}3 \\ \bottomrule \end{tabular} \end{enumerate} \end{enumerate} \section{Directories and LDAP} \label{sec:ldap} Many of you have not completed the tutorial sheet ``\LDAP Filters and Searching \LDAP directories.'' I suggest that you complete it. \end{document}