9494import com .cloud .agent .api .PingCommand ;
9595import com .cloud .agent .api .PingRoutingCommand ;
9696import com .cloud .agent .api .PingRoutingWithNwGroupsCommand ;
97+ import com .cloud .agent .api .PingRoutingWithOvsCommand ;
9798import com .cloud .agent .api .PingTestCommand ;
9899import com .cloud .agent .api .PoolEjectCommand ;
99100import com .cloud .agent .api .PrepareForMigrationAnswer ;
159160import com .cloud .network .Networks .BroadcastDomainType ;
160161import com .cloud .network .Networks .IsolationType ;
161162import com .cloud .network .Networks .TrafficType ;
163+ import com .cloud .network .ovs .OvsCreateGreTunnelAnswer ;
162164import com .cloud .network .ovs .OvsCreateGreTunnelCommand ;
165+ import com .cloud .network .ovs .OvsDeleteFlowCommand ;
166+ import com .cloud .network .ovs .OvsSetTagAndFlowAnswer ;
163167import com .cloud .network .ovs .OvsSetTagAndFlowCommand ;
164168import com .cloud .resource .ServerResource ;
165169import com .cloud .storage .Storage ;
@@ -247,6 +251,7 @@ public abstract class CitrixResourceBase implements ServerResource {
247251
248252 protected StorageLayer _storage ;
249253 protected boolean _canBridgeFirewall = false ;
254+ protected boolean _isOvs = false ;
250255 protected HashMap <StoragePoolType , StoragePoolResource > _pools = new HashMap <StoragePoolType , StoragePoolResource >(5 );
251256
252257 public enum SRType {
@@ -449,6 +454,8 @@ public Answer executeRequest(Command cmd) {
449454 return execute ((OvsCreateGreTunnelCommand )cmd );
450455 } else if (cmd instanceof OvsSetTagAndFlowCommand ) {
451456 return execute ((OvsSetTagAndFlowCommand )cmd );
457+ } else if (cmd instanceof OvsDeleteFlowCommand ) {
458+ return execute ((OvsDeleteFlowCommand )cmd );
452459 } else {
453460 return Answer .createUnsupportedCommandAnswer (cmd );
454461 }
@@ -3312,9 +3319,12 @@ public PingCommand getCurrentStatus(long id) {
33123319 if (newStates == null ) {
33133320 newStates = new HashMap <String , State >();
33143321 }
3315- if (!_canBridgeFirewall ) {
3322+ if (!_canBridgeFirewall && ! _isOvs ) {
33163323 return new PingRoutingCommand (getType (), id , newStates );
3317- } else {
3324+ } else if (_isOvs ) {
3325+ List <Pair <String , Long >>ovsStates = ovsFullSyncStates ();
3326+ return new PingRoutingWithOvsCommand (getType (), id , newStates , ovsStates );
3327+ }else {
33183328 HashMap <String , Pair <Long , Long >> nwGrpStates = syncNetworkGroups (conn , id );
33193329 return new PingRoutingWithNwGroupsCommand (getType (), id , newStates , nwGrpStates );
33203330 }
@@ -3820,7 +3830,61 @@ protected boolean can_bridge_firewall(Connection conn) {
38203830 return Boolean .valueOf (callHostPlugin (conn , "vmops" , "can_bridge_firewall" , "host_uuid" , _host .uuid ));
38213831 }
38223832
3823- private Answer execute (OvsSetTagAndFlowCommand cmd ) {
3833+ private Answer execute (OvsDeleteFlowCommand cmd ) {
3834+ _isOvs = true ;
3835+
3836+ Connection conn = getConnection ();
3837+ try {
3838+ String nwName = Networks .BroadcastScheme .VSwitch .toString ();
3839+ Network nw = getNetworkByName (conn , nwName );
3840+ assert nw != null : "Why there is no vswith network ???" ;
3841+ String bridge = nw .getBridge (conn );
3842+ String result = callHostPlugin (conn , "vmops" , "ovs_delete_flow" , "bridge" , bridge ,
3843+ "vmName" , cmd .getVmName ());
3844+
3845+ if (result .equalsIgnoreCase ("SUCCESS" )) {
3846+ return new Answer (cmd , true , "success to delete flows for " + cmd .getVmName ());
3847+ } else {
3848+ return new Answer (cmd , false , result );
3849+ }
3850+ } catch (Exception e ) {
3851+ e .printStackTrace ();
3852+ }
3853+ return new Answer (cmd , false , "failed to delete flow for " + cmd .getVmName ());
3854+ }
3855+
3856+ private List <Pair <String , Long >> ovsFullSyncStates () {
3857+ Connection conn = getConnection ();
3858+ try {
3859+ String result = callHostPlugin (conn , "vmops" , "ovs_get_vm_log" , "host_uuid" , _host .uuid );
3860+ String [] logs = result != null ?result .split (";" ): new String [0 ];
3861+ List <Pair <String , Long >> states = new ArrayList <Pair <String , Long >>();
3862+ for (String log : logs ){
3863+ String [] info = log .split ("," );
3864+ if (info .length != 4 ) {
3865+ s_logger .warn ("Wrong element number in ovs log" );
3866+ continue ;
3867+ }
3868+
3869+ //','.join([bridge, vmName, vmId, seqno])
3870+ try {
3871+ states .add (new Pair <String ,Long >(info [0 ], Long .parseLong (info [3 ])));
3872+ } catch (NumberFormatException nfe ) {
3873+ states .add (new Pair <String ,Long >(info [0 ], -1L ));
3874+ }
3875+ }
3876+
3877+ return states ;
3878+ } catch (Exception e ) {
3879+ e .printStackTrace ();
3880+ }
3881+
3882+ return null ;
3883+ }
3884+
3885+ private OvsSetTagAndFlowAnswer execute (OvsSetTagAndFlowCommand cmd ) {
3886+ _isOvs = true ;
3887+
38243888 Connection conn = getConnection ();
38253889 try {
38263890 String nwName = Networks .BroadcastScheme .VSwitch .toString ();
@@ -3833,48 +3897,47 @@ private Answer execute(OvsSetTagAndFlowCommand cmd) {
38333897 * plugin side
38343898 */
38353899 String result = callHostPlugin (conn , "vmops" , "ovs_set_tag_and_flow" , "bridge" , bridge ,
3836- "vmName" , cmd .getVmName (), "vlans" , cmd .getVlans ());
3900+ "vmName" , cmd .getVmName (), "vlans" , cmd .getVlans (), "seqno" , cmd . getSeqNo () );
38373901 s_logger .debug ("set flow for " + cmd .getVmName () + " " + result );
38383902
38393903 if (result .equalsIgnoreCase ("SUCCESS" )) {
3840- return new Answer (cmd , true , "Set flow for " + cmd .getVmName ()
3841- + " success, vlans:" + cmd .getVlans ());
3904+ return new OvsSetTagAndFlowAnswer (cmd , true , result );
38423905 } else {
3843- return new Answer (cmd , false , "Set flow for " + cmd .getVmName ()
3844- + " failed, vlans:" + cmd .getVlans ());
3906+ return new OvsSetTagAndFlowAnswer (cmd , false , result );
38453907 }
38463908 } catch (Exception e ) {
38473909 e .printStackTrace ();
38483910 }
38493911
3850- return new Answer (cmd , false , "Set flow for " + cmd .getVmName ()
3851- + " failed, vlans:" + cmd .getVlans ());
3912+ return new OvsSetTagAndFlowAnswer (cmd , false , "EXCEPTION" );
38523913 }
38533914
3854- private Answer execute (OvsCreateGreTunnelCommand cmd ) {
3915+
3916+ private OvsCreateGreTunnelAnswer execute (OvsCreateGreTunnelCommand cmd ) {
3917+ _isOvs = true ;
3918+
38553919 Connection conn = getConnection ();
3920+ String bridge = "unkonwn" ;
38563921 try {
3857- String nwName = Networks .BroadcastScheme .VSwitch .toString ();
3858- Network nw = getNetworkByName (conn , nwName );
3859- if (nw == null ) {
3860- nw = setupvSwitchNetwork (conn );
3861- }
3922+ //TODO: we may store vswtich network to _host
3923+ Network nw = setupvSwitchNetwork (conn );
3924+ bridge = nw .getBridge (conn );
38623925
38633926 String result = callHostPlugin (conn , "vmops" , "vlanRemapUtils" ,
3864- "op" , "createGRE" , "bridge" , nw . getBridge ( conn ) ,
3927+ "op" , "createGRE" , "bridge" , bridge ,
38653928 "remoteIP" , cmd .getRemoteIp (), "greKey" , cmd .getKey ());
3866- if (result .equalsIgnoreCase ("SUCCESS" )) {
3867- return new Answer (cmd , true , "create gre tunnel to "
3868- + cmd .getRemoteIp () + " success" );
3929+ if (result .equalsIgnoreCase ("SUCCESS" ) || result .equalsIgnoreCase ("TUNNEL_EXISTED" )) {
3930+ return new OvsCreateGreTunnelAnswer (cmd , true , result );
38693931 } else {
3870- return new Answer (cmd , false , "create gre tunnel to "
3871- + cmd .getRemoteIp () + " failed" );
3932+ return new OvsCreateGreTunnelAnswer (cmd , false , result ,
3933+ _host . ip , cmd .getRemoteIp (), bridge , cmd . getKey () );
38723934 }
38733935 } catch (Exception e ) {
38743936 e .printStackTrace ();
38753937 }
38763938
3877- return new Answer (cmd , false , "create gre tunnel to " + cmd .getRemoteIp () + " failed" );
3939+ return new OvsCreateGreTunnelAnswer (cmd , false , "EXCEPTION" , _host .ip ,
3940+ cmd .getRemoteIp (), bridge , cmd .getKey ());
38783941 }
38793942
38803943 private Answer execute (SecurityIngressRulesCmd cmd ) {
0 commit comments