- Protecting Valuable Resources
- Interfaces: Action-Packed Entities
- Configuring IP Addresses
- Solution Introduction and the Flyweight Pattern
- A Generic Network Link
- A Generic Network Link Context
- A Real Network Link
- The GenericLink Implementation
- The GenericLinkContext Implementation
- The RealLink Implementation
- Bringing the Code Together
- Conclusion
- Additional Reading
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 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.