Class Configurator


  • public class Configurator
    extends java.lang.Object
    The task if this class is to setup and configure the protocol stack. A string describing the desired setup, which is both the layering and the configuration of each layer, is given to the configurator which creates and configures the protocol stack and returns a reference to the top layer (Protocol).

    Future functionality will include the capability to dynamically modify the layering of the protocol stack and the properties of each layer.

    Author:
    Bela Ban, Richard Achmatowicz
    • Field Detail

      • log

        protected static final Log log
      • skip_setting_default_values

        protected static boolean skip_setting_default_values
    • Constructor Detail

      • Configurator

        public Configurator()
      • Configurator

        public Configurator​(ProtocolStack protocolStack)
    • Method Detail

      • skipSettingDefaultValues

        public static boolean skipSettingDefaultValues()
      • skipSettingDefaultValues

        public static void skipSettingDefaultValues​(boolean f)
      • setupProtocolStack

        public Protocol setupProtocolStack​(java.util.List<ProtocolConfiguration> config)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setupProtocolStack

        public static Protocol setupProtocolStack​(java.util.List<ProtocolConfiguration> protocol_configs,
                                                  ProtocolStack st)
                                           throws java.lang.Exception
        Sets up the protocol stack. Each ProtocolConfiguration has the protocol name and a map of attribute names and values (strings). Reflection is used to find the right fields (or setters) based on attribute names, and set them (by converting the attribute value to the proper object).
        Throws:
        java.lang.Exception
      • createProtocol

        public static Protocol createProtocol​(java.lang.String prot_spec,
                                              ProtocolStack stack)
                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • createProtocol

        public static Protocol createProtocol​(java.lang.String prot_spec,
                                              ProtocolStack stack,
                                              boolean init_attrs)
                                       throws java.lang.Exception
        Creates a new protocol given the protocol specification. Initializes the properties and starts the up and down handler threads.
        Parameters:
        prot_spec - The specification of the protocol. Same convention as for specifying a protocol stack. An exception will be thrown if the class cannot be created. Example:
        "VERIFY_SUSPECT(timeout=1500)"
        Note that no colons (:) have to be specified
        stack - The protocol stack
        Returns:
        Protocol The newly created protocol
        Throws:
        java.lang.Exception - Will be thrown when the new protocol cannot be created
      • createProtocolsAndInitializeAttrs

        public static java.util.List<Protocol> createProtocolsAndInitializeAttrs​(java.util.List<ProtocolConfiguration> cfgs,
                                                                                 ProtocolStack st)
                                                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • connectProtocols

        public static Protocol connectProtocols​(java.util.List<Protocol> protocol_list)
                                         throws java.lang.Exception
        Creates a protocol stack by iterating through the protocol list and connecting adjacent layers. The list starts with the topmost layer and has the bottommost layer at the tail.
        Parameters:
        protocol_list - List of Protocol elements (from top to bottom)
        Returns:
        Protocol stack
        Throws:
        java.lang.Exception
      • createProtocols

        public static java.util.List<Protocol> createProtocols​(java.util.List<ProtocolConfiguration> protocol_configs,
                                                               ProtocolStack stack)
                                                        throws java.lang.Exception
        Takes a list of configurations, creates a protocol for each and returns all protocols in a list.
        Parameters:
        protocol_configs - A list of ProtocolConfigurations
        stack - The protocol stack
        Returns:
        List of Protocols
        Throws:
        java.lang.Exception
      • initializeAttrs

        public static void initializeAttrs​(Protocol prot,
                                           ProtocolConfiguration config,
                                           StackType ip_version)
                                    throws java.lang.Exception
        Sets the attributes in a given protocol from properties
        Throws:
        java.lang.Exception
      • initializeAttrs

        public static void initializeAttrs​(java.lang.Object obj,
                                           java.util.Map<java.lang.String,​java.lang.String> properties,
                                           StackType ip_version)
                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • sanityCheck

        public static void sanityCheck​(java.util.List<Protocol> protocols)
                                throws java.lang.Exception
        Throws an exception if sanity check fails. Possible sanity check is uniqueness of all protocol names
        Throws:
        java.lang.Exception
      • printEvents

        protected static java.lang.String printEvents​(java.util.List<java.lang.Integer> events)
      • removeProvidedUpServices

        protected static void removeProvidedUpServices​(Protocol protocol,
                                                       java.util.List<java.lang.Integer> events)
        Removes all events provided by the protocol below protocol from events
        Parameters:
        protocol -
        events -
      • removeProvidedDownServices

        protected static void removeProvidedDownServices​(Protocol protocol,
                                                         java.util.List<java.lang.Integer> events)
        Removes all events provided by the protocol above protocol from events
        Parameters:
        protocol -
        events -
      • getAddresses

        public static java.util.Collection<java.net.InetAddress> getAddresses​(java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​Configurator.InetAddressInfo>> map)
                                                                       throws java.lang.Exception
        Returns all inet addresses found
        Throws:
        java.lang.Exception
      • createInetAddressMap

        public static java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​Configurator.InetAddressInfo>> createInetAddressMap​(java.util.List<ProtocolConfiguration> protocol_configs,
                                                                                                                                                    java.util.List<Protocol> protocols)
                                                                                                                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getInetAddresses

        public static java.util.List<java.net.InetAddress> getInetAddresses​(java.util.List<Protocol> protocols)
                                                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getInetAddresses2

        public static java.util.Map<java.lang.String,​java.net.InetAddress> getInetAddresses2​(java.util.List<Protocol> protocols)
        Returns a map of protocol.attr/InetAddress tuples
      • isInetAddressOrCompatibleType

        public static boolean isInetAddressOrCompatibleType​(java.lang.Class<?> c)
      • setDefaultAddressValues

        public static void setDefaultAddressValues​(java.util.List<Protocol> protocols,
                                                   StackType ip_version)
                                            throws java.lang.Exception
        Processes fields and methods which are inet address related, and assigns them default values defined by (Property.defaultValueIPv4() and Property.defaultValueIPv6()). This method does the following: - find all properties which have no value assigned - generate a value for the field using the property converter for that property and assign it to the field
        Throws:
        java.lang.Exception
      • setDefaultAddressValues

        public static void setDefaultAddressValues​(java.lang.Object obj,
                                                   StackType ip_version)
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setDefaultAddressValuesMethods

        protected static void setDefaultAddressValuesMethods​(java.lang.Object obj,
                                                             StackType ip_version,
                                                             java.net.InetAddress default_ip_address)
                                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setDefaultAddressValuesFields

        protected static void setDefaultAddressValuesFields​(java.lang.Object obj,
                                                            StackType ip_version,
                                                            java.net.InetAddress default_ip_address)
                                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • ensureValidBindAddresses

        public static void ensureValidBindAddresses​(java.util.List<Protocol> protocols)
                                             throws java.lang.Exception
        Makes sure that all fields annotated with @LocalAddress is (1) an InetAddress and (2) a valid address on any local network interface
        Throws:
        java.lang.Exception
      • getValueFromObject

        public static <T> T getValueFromObject​(java.lang.Object obj,
                                               java.lang.reflect.Field field)
                                        throws java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalAccessException
      • getValueFromObject

        public static <T> T getValueFromObject​(java.lang.Object obj,
                                               java.lang.String field_name)
                                        throws java.lang.IllegalAccessException
        Throws:
        java.lang.IllegalAccessException
      • resolveAndInvokePropertyMethods

        public static void resolveAndInvokePropertyMethods​(java.lang.Object obj,
                                                           java.util.Map<java.lang.String,​java.lang.String> props,
                                                           StackType ip_version)
                                                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • resolveAndInvokePropertyMethod

        public static void resolveAndInvokePropertyMethod​(java.lang.Object obj,
                                                          java.lang.reflect.Method method,
                                                          java.util.Map<java.lang.String,​java.lang.String> props,
                                                          StackType ip_version)
                                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • resolveAndAssignFields

        public static void resolveAndAssignFields​(java.lang.Object obj,
                                                  java.util.Map<java.lang.String,​java.lang.String> props,
                                                  StackType ip_version)
                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • resolveAndAssignField

        public static void resolveAndAssignField​(java.lang.Object obj,
                                                 java.lang.reflect.Field field,
                                                 java.util.Map<java.lang.String,​java.lang.String> props,
                                                 StackType ip_version)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isSetPropertyMethod

        public static boolean isSetPropertyMethod​(java.lang.reflect.Method method,
                                                  java.lang.Class<?> enclosing_clazz)