<s> """<STR_LIT>""" <EOL> from ryu . base import app_manager <EOL> from ryu . controller import handler <EOL> from ryu . lib import dpid as lib_dpid <EOL> from ryu . lib import hub <EOL> from ryu . lib . packet import vrrp <EOL> from ryu . services . protocols . vrrp import api as vrrp_api <EOL> from ryu . services . protocols . vrrp import event as vrrp_event <EOL> from ryu . services . protocols . vrrp import monitor_openflow <EOL> from ryu . topology import event as topo_event <EOL> from ryu . topology import api as topo_api <EOL> from . import vrrp_common <EOL> class VRRPConfigApp ( vrrp_common . VRRPCommon ) : <EOL> _IFNAME0 = <NUM_LIT:0> <EOL> _IFNAME1 = <NUM_LIT:1> <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( VRRPConfigApp , self ) . __init__ ( * args , ** kwargs ) <EOL> self . start_main = False <EOL> @ handler . set_ev_cls ( topo_event . EventSwitchEnter ) <EOL> def _switch_enter_handler ( self , ev ) : <EOL> if self . start_main : <EOL> return <EOL> switches = topo_api . get_switch ( self ) <EOL> if len ( switches ) < <NUM_LIT:2> : <EOL> return <EOL> self . start_main = True <EOL> app_mgr = app_manager . AppManager . get_instance ( ) <EOL> self . logger . debug ( '<STR_LIT:%s>' , app_mgr . applications ) <EOL> self . switches = app_mgr . applications [ '<STR_LIT>' ] <EOL> hub . spawn ( self . _main ) <EOL> def _configure_vrrp_router ( self , vrrp_version , priority , <EOL> ip_addr , switch_index , vrid ) : <EOL> switches = self . switches <EOL> self . logger . debug ( '<STR_LIT:%s>' , switches . dps ) <EOL> dpid = sorted ( switches . dps . keys ( ) ) [ switch_index ] <EOL> self . logger . debug ( '<STR_LIT:%s>' , lib_dpid . dpid_to_str ( dpid ) ) <EOL> self . logger . debug ( '<STR_LIT:%s>' , switches . port_state ) <EOL> port_no = sorted ( switches . port_state [ dpid ] . keys ( ) ) [ <NUM_LIT:0> ] <EOL> self . logger . debug ( '<STR_LIT>' , port_no ) <EOL> port = switches . port_state [ dpid ] [ port_no ] <EOL> self . logger . debug ( '<STR_LIT:%s>' , port ) <EOL> mac = port . hw_addr <EOL> self . logger . debug ( '<STR_LIT:%s>' , mac ) <EOL> interface = vrrp_event . VRRPInterfaceOpenFlow ( <EOL> mac , ip_addr , None , dpid , port_no ) <EOL> self . logger . debug ( '<STR_LIT:%s>' , interface ) <EOL> config = vrrp_event . VRRPConfig ( <EOL> version = vrrp_version , vrid = vrid , priority = priority , <EOL> ip_addresses = [ ip_addr ] ) <EOL> self . logger . debug ( '<STR_LIT:%s>' , config ) <EOL> rep = vrrp_api . vrrp_config ( self , interface , config ) <EOL> self . logger . debug ( '<STR_LIT:%s>' , rep ) <EOL> return rep </s>
