Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

  • Print
  • + Share This
Like this article? We recommend

Bringing the Code Together

Listing 8 illustrates the complete listing of the main() function. This describes the instantiation of a GenericLinkContext object and two RealLink objects. We assign two IP address ranges, one for each of the two RealLink objects. After this, we list the IP address ranges by calling the member function GetAllIPAddresses() for each instance of RealLink.

Listing 8 The main() function.

int _tmain(int argc, _TCHAR* argv[])
{
  GenericLinkContext* aLinkContext = new GenericLinkContext();

  RealLink* aLink = new RealLink("MPLS", "NodeA", "NodeB", 
    "ifA", "ifB", aLinkContext);

  RealLink* anotherLink = new RealLink("MPLS", "NodeC", "NodeD", 
    "ifP", "ifQ", aLinkContext);

  aLinkContext->SetAddressRange(
    anotherLink->mySlotNumber, 
    "11.61.1.x", 6, 9);
  
  aLinkContext->SetAddressRange(
    aLink->mySlotNumber, 
    "10.81.1.x", 0, 7);

  char ipAddressRange[BUFFER_LENGTH];

  aLink->GetAllIPAddresses(ipAddressRange);
  printf ("For aLink, IP Address range is %s\n", ipAddressRange);

  anotherLink->GetAllIPAddresses(ipAddressRange);
  printf ("For anotherLink, IP Address range is %s\n", ipAddressRange);
  
  return 0;
}

Figure 3 shows the program output from executing the code in Listing 8.

Figure 3

Figure 3 Two links each with an IP address range.

In Figure 3, the two RealLink objects have been assigned individual and independent IP address ranges. How this code might be introduced into a commercial system is as an adjunct to node management. The flyweight code would assign and calculate the IP address ranges for links. Then the back-end code would configure the real interfaces with the data. I’ve described how to configure IP addresses initially, but there’s no reason why the same code couldn’t be used for renumbering IP networks.

  • + Share This
  • 🔖 Save To Your Account