CumulusTorSwitchService implements ISwitchService { @Override public SwitchOspfConfig getOspf( SwitchNode switchNode ) throws HmsException { SwitchOspfConfig ospf = new SwitchOspfConfig(); SwitchOspfGlobalConfig globalConfig = new SwitchOspfGlobalConfig(); SwitchOspfNetworkConfig networkConfig = null; SwitchOspfInterfaceConfig interfaceConfig = null; List<SwitchOspfNetworkConfig> networkConfigList = new ArrayList<SwitchOspfNetworkConfig>(); List<SwitchOspfInterfaceConfig> interfaceConfigList = new ArrayList<SwitchOspfInterfaceConfig>(); SwitchSession switchSession = getSession( switchNode ); String[] quaggaConfig = null; String[] tokens = null; ospf.setGlobal( globalConfig ); globalConfig.setInterfaces( interfaceConfigList ); globalConfig.setNetworks( networkConfigList ); String[] commandSet = { "echo '{password}' | sudo -S cat /etc/quagga/Quagga.conf".replaceAll( "\\{password\\}", switchNode.getPassword() ), CumulusConstants.LIST_QUAGGA_DAEMONS_COMMAND.replaceAll( "\\{password\\}", switchNode.getPassword() ) }; String[][] combinedOutput = GetMultipleCmdResults( switchSession, commandSet ); if ( combinedOutput.length < 1 ) { throw new HmsException( "Failed to retrieve necessary information from switch" ); } quaggaConfig = combinedOutput[0]; if ( ( quaggaConfig.length == 0 ) || quaggaConfig[0].matches( ".*No such file or directory.*" ) ) { return ospf; } for ( String line : quaggaConfig ) { line = line.trim(); if ( line.matches( "^router-id.*" ) ) { tokens = line.split( "\\s+" ); if ( tokens.length >= 2 ) globalConfig.setRouterId( tokens[1] ); ospf.setEnabled( true ); } else if ( line.matches( ".*passive-interface default.*" ) ) { if ( line.startsWith( "no" ) ) globalConfig.setDefaultMode( OspfMode.ACTIVE ); else globalConfig.setDefaultMode( OspfMode.PASSIVE ); } else if ( line.matches( ".*network .*area.*" ) ) { networkConfig = new SwitchOspfNetworkConfig(); tokens = line.split( "\\s+" ); if ( tokens.length < 4 ) continue; networkConfig.setArea( tokens[3] ); networkConfig.setNetwork( tokens[1] ); networkConfigList.add( networkConfig ); } else if ( line.matches( ".*passive-interface.*swp[0-9]+.*" ) ) { interfaceConfig = new SwitchOspfInterfaceConfig(); tokens = line.split( "\\s+" ); if ( tokens.length < 2 ) continue; if ( line.startsWith( "no" ) ) interfaceConfig.setMode( InterfaceMode.ACTIVE ); else interfaceConfig.setMode( InterfaceMode.PASSIVE ); interfaceConfig.setName( tokens[tokens.length - 1] ); interfaceConfigList.add( interfaceConfig ); } } return ospf; }  @Override String getSwitchType(); @Override List<SwitchType> getSupportedSwitchTypes(); @Override boolean discoverSwitch( SwitchNode switchNode ); @Override SwitchSession getSession( SwitchNode switchNode ); @Override boolean isPoweredOn( SwitchNode switchNode ); @Override SwitchOsInfo getSwitchOsInfo( SwitchNode switchNode ); @Override SwitchHardwareInfo getSwitchHardwareInfo( SwitchNode switchNode ); @Override boolean updateSwitchIpAddress( SwitchNode switchNode, String ipAddress, String netmask, String gateway ); @Override boolean setPassword( SwitchNode switchNode, String username, String newPassword ); @Override boolean updateSwitchTimeServer( SwitchNode switchNode, String timeServer ); @Override List<String> getSwitchPortList( SwitchNode switchNode ); @Override SwitchPort getSwitchPort( SwitchNode switchNode, String portName ); @Override PortStatus getSwitchPortStatus( SwitchNode switchNode, String portName ); @Override boolean setSwitchPortStatus( SwitchNode switchNode, String portName, PortStatus portStatus ); @Override boolean updateSwitchPort( SwitchNode switchNode, String portName, SwitchPort portInfo ); @Override SwitchVlan getSwitchVlan( SwitchNode switchNode, String vlanName ); @Override List<String> getSwitchVlans( SwitchNode switchNode ); @Override List<SwitchVlan> getSwitchVlansBulk( SwitchNode switchNode ); @Override boolean createVlan( SwitchNode switchNode, SwitchVlan vlan ); @Override boolean updateVlan( SwitchNode switchNode, String vlanName, SwitchVlan vlan ); @Override boolean deleteVlan( SwitchNode switchNode, String vlanName ); @Override List<String> getSwitchLacpGroups( SwitchNode switchNode ); @Override SwitchLacpGroup getSwitchLacpGroup( SwitchNode switchNode, String lacpGroupName ); @Override boolean createLacpGroup( SwitchNode switchNode, SwitchLacpGroup lacpGroup ); @Override boolean deleteLacpGroup( SwitchNode switchNode, String lacpGroupName ); @Override boolean reboot( SwitchNode switchNode ); @Override boolean upgrade( SwitchNode switchNode, SwitchUpgradeInfo upgradeInfo ); @Deprecated @Override boolean applyNetworkConfiguration( SwitchNode switchNode, SwitchNetworkConfiguration networkConfiguration ); @Override List<SwitchVxlan> getSwitchVxlans( SwitchNode switchNode ); @Override List<SwitchVxlan> getSwitchVxlansMatchingVlan( SwitchNode switchNode, String vlanName ); @Override boolean createVxlan( SwitchNode switchNode, SwitchVxlan vxlan ); @Override boolean deleteVxlan( SwitchNode switchNode, String vxlanName, String vlanName ); @Override void deletePortOrBondFromVlan( SwitchNode switchNode, String vlanId, String portOrBondName ); @Override void deletePortFromLacpGroup( SwitchNode switchNode, String lacpGroupName, String portName ); @Override List<SwitchPort> getSwitchPortListBulk( SwitchNode switchNode ); @Override boolean configureOspf( SwitchNode switchNode, SwitchOspfConfig ospf ); @Override SwitchOspfConfig getOspf( SwitchNode switchNode ); @Override boolean configureBgp( SwitchNode switchNode, SwitchBgpConfig bgp ); @Override SwitchBgpConfig getBgpConfiguration( SwitchNode switchNode ); @Override SwitchSensorInfo getSwitchSensorInfo( SwitchNode switchNode ); @Override boolean configureMclag( SwitchNode switchNode, SwitchMclagInfo mclag ); @Override SwitchMclagInfo getMclagStatus( SwitchNode switchNode ); @Override void applySwitchBulkConfigs( SwitchNode switchNode, List<PluginSwitchBulkConfig> switchBulkConfigs ); @Override void configureIpv4DefaultRoute( SwitchNode switchNode, String gateway, String portId ); @Override void deleteIpv4DefaultRoute( SwitchNode switchNode ); @Override List<ServerComponentEvent> getComponentSwitchEventList( ServiceHmsNode serviceNode,
                                                                   SwitchComponentEnum component ); @Override List<HmsApi> getSupportedHmsSwitchApi( ServiceHmsNode serviceNode ); @Override void setSwitchTime( SwitchNode switchNode, long time ); @Override void configureSnmp( SwitchNode switchNode, SwitchSnmpConfig config ); @Override SwitchSnmpConfig getSnmp( SwitchNode switchNode );  }
@Test public void testGetOspf() { SwitchOspfConfig ospfConfig_Obj = null; try { ospfConfig_Obj = cumulusTorSwitchService_Obj.getOspf( switchNode_Obj ); assertNotNull( "The ospfConfig is null", ospfConfig_Obj ); if ( ospfConfig_Obj != null ) { logger.info( "class name: " + ospfConfig_Obj.getClass().getName() ); SwitchOspfGlobalConfig globalConfig = ospfConfig_Obj.getGlobal(); assertNotNull( "The global config is null", globalConfig ); logger.info( "Router Id: " + globalConfig.getRouterId() ); logger.info( "Default Mode: " + globalConfig.getDefaultMode() ); List<SwitchOspfNetworkConfig> networkConfigList = globalConfig.getNetworks(); List<SwitchOspfInterfaceConfig> interfaceConfigList = globalConfig.getInterfaces(); assertNotNull( "The network config list is null", networkConfigList ); assertNotNull( "The interface config list is null", interfaceConfigList ); for ( int i = 0; i < networkConfigList.size(); i++ ) { logger.info( "Network: " + networkConfigList.get( i ).getNetwork() ); logger.info( "Area: " + networkConfigList.get( i ).getArea() ); } for ( int i = 0; i < interfaceConfigList.size(); i++ ) { logger.info( "Name: " + interfaceConfigList.get( i ).getName() ); InterfaceMode interfaceMode = interfaceConfigList.get( i ).getMode(); logger.info( "InterfaceMode name: " + interfaceMode.getClass().getName() ); } } } catch ( Exception e ) { logger.info( "Error while getting Ospf information: " + e.toString() ); if ( PRINT_STACK_TRACE ) logger.debug( e.getStackTrace() ); if ( FAIL_ON_EXCEPTION ) fail(); } }