148148import com .cloud .agent .api .OvsSetTagAndFlowAnswer ;
149149import com .cloud .agent .api .OvsSetTagAndFlowCommand ;
150150import com .cloud .agent .api .OvsSetupBridgeCommand ;
151+ import com .cloud .agent .api .OvsVpcPhysicalTopologyConfigCommand ;
151152import com .cloud .agent .api .PerformanceMonitorAnswer ;
152153import com .cloud .agent .api .PerformanceMonitorCommand ;
153154import com .cloud .agent .api .PingCommand ;
@@ -507,6 +508,8 @@ public Answer executeRequest(Command cmd) {
507508 return execute ((OvsSetTagAndFlowCommand )cmd );
508509 } else if (clazz == OvsDeleteFlowCommand .class ) {
509510 return execute ((OvsDeleteFlowCommand )cmd );
511+ } else if (clazz == OvsVpcPhysicalTopologyConfigCommand .class ) {
512+ return execute ((OvsVpcPhysicalTopologyConfigCommand ) cmd );
510513 } else if (clazz == CleanupNetworkRulesCmd .class ) {
511514 return execute ((CleanupNetworkRulesCmd )cmd );
512515 } else if (clazz == NetworkRulesSystemVmCommand .class ) {
@@ -964,15 +967,14 @@ private synchronized Network setupvSwitchNetwork(Connection conn) {
964967 /**
965968 * This method just creates a XenServer network following the tunnel network naming convention
966969 */
967- private synchronized Network findOrCreateTunnelNetwork (Connection conn , long key ) {
970+ private synchronized Network findOrCreateTunnelNetwork (Connection conn , String nwName ) {
968971 try {
969- String nwName = "OVSTunnel" + key ;
970972 Network nw = null ;
971973 Network .Record rec = new Network .Record ();
972974 Set <Network > networks = Network .getByNameLabel (conn , nwName );
973975
974976 if (networks .size () == 0 ) {
975- rec .nameDescription = "tunnel network id# " + key ;
977+ rec .nameDescription = "tunnel network id# " + nwName ;
976978 rec .nameLabel = nwName ;
977979 //Initialize the ovs-host-setup to avoid error when doing get-param in plugin
978980 Map <String , String > otherConfig = new HashMap <String , String >();
@@ -981,7 +983,7 @@ private synchronized Network findOrCreateTunnelNetwork(Connection conn, long key
981983 nw = Network .create (conn , rec );
982984 // Plug dom0 vif only when creating network
983985 if (!is_xcp ())
984- enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + key );
986+ enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + nwName );
985987 s_logger .debug ("### Xen Server network for tunnels created:" + nwName );
986988 } else {
987989 nw = networks .iterator ().next ();
@@ -997,10 +999,10 @@ private synchronized Network findOrCreateTunnelNetwork(Connection conn, long key
997999 /**
9981000 * This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network
9991001 */
1000- private synchronized Network configureTunnelNetwork (Connection conn , long networkId , long hostId , int key ) {
1002+ private synchronized Network configureTunnelNetwork (Connection conn , long networkId , long hostId , String bridgeName ) {
10011003 try {
1002- Network nw = findOrCreateTunnelNetwork (conn , key );
1003- String nwName = "OVSTunnel" + key ;
1004+ Network nw = findOrCreateTunnelNetwork (conn , bridgeName );
1005+ String nwName = bridgeName ;
10041006 //Invoke plugin to setup the bridge which will be used by this network
10051007 String bridge = nw .getBridge (conn );
10061008 Map <String , String > nwOtherConfig = nw .getOtherConfig (conn );
@@ -1018,11 +1020,20 @@ private synchronized Network configureTunnelNetwork(Connection conn, long networ
10181020 if (!configured ) {
10191021 // Plug dom0 vif only if not done before for network and host
10201022 if (!is_xcp ())
1021- enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + key );
1022- String result = callHostPlugin (conn , "ovstunnel" , "setup_ovs_bridge" , "bridge" , bridge ,
1023- "key" , String .valueOf (key ),
1024- "xs_nw_uuid" , nw .getUuid (conn ),
1025- "cs_host_id" , ((Long )hostId ).toString ());
1023+ enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + bridgeName );
1024+ String result ;
1025+ if (bridgeName .startsWith ("OVS-DR-VPC-Bridge" )) {
1026+ result = callHostPlugin (conn , "ovstunnel" , "setup_ovs_bridge_for_distributed_routing" , "bridge" , bridge ,
1027+ "key" , bridgeName ,
1028+ "xs_nw_uuid" , nw .getUuid (conn ),
1029+ "cs_host_id" , ((Long )hostId ).toString ());
1030+ } else {
1031+ result = callHostPlugin (conn , "ovstunnel" , "setup_ovs_bridge" , "bridge" , bridge ,
1032+ "key" , bridgeName ,
1033+ "xs_nw_uuid" , nw .getUuid (conn ),
1034+ "cs_host_id" , ((Long )hostId ).toString ());
1035+ }
1036+
10261037 //Note down the fact that the ovs bridge has been setup
10271038 String [] res = result .split (":" );
10281039 if (res .length != 2 || !res [0 ].equalsIgnoreCase ("SUCCESS" )) {
@@ -1037,9 +1048,9 @@ private synchronized Network configureTunnelNetwork(Connection conn, long networ
10371048 }
10381049 }
10391050
1040- private synchronized void destroyTunnelNetwork (Connection conn , int key ) {
1051+ private synchronized void destroyTunnelNetwork (Connection conn , String bridgeName ) {
10411052 try {
1042- Network nw = findOrCreateTunnelNetwork (conn , key );
1053+ Network nw = findOrCreateTunnelNetwork (conn , bridgeName );
10431054 String bridge = nw .getBridge (conn );
10441055 String result = callHostPlugin (conn , "ovstunnel" , "destroy_ovs_bridge" , "bridge" , bridge );
10451056 String [] res = result .split (":" );
@@ -1079,8 +1090,7 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException,
10791090 _isOvs = true ;
10801091 return setupvSwitchNetwork (conn );
10811092 } else {
1082- long vnetId = Long .parseLong (BroadcastDomainType .getValue (uri ));
1083- return findOrCreateTunnelNetwork (conn , vnetId );
1093+ return findOrCreateTunnelNetwork (conn , getOvsTunnelNetworkName (BroadcastDomainType .getValue (uri )));
10841094 }
10851095 } else if (type == BroadcastDomainType .Storage ) {
10861096 if (uri == null ) {
@@ -1102,6 +1112,19 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException,
11021112 throw new CloudRuntimeException ("Unable to support this type of network broadcast domain: " + nic .getBroadcastUri ());
11031113 }
11041114
1115+ private String getOvsTunnelNetworkName (String broadcastUri ) {
1116+ if (broadcastUri .contains ("." )) {
1117+ String [] parts = broadcastUri .split ("." );
1118+ return "OVS-DR-VPC-Bridge" +parts [0 ];
1119+ } else {
1120+ try {
1121+ return "OVSTunnel" + broadcastUri ;
1122+ } catch (Exception e ) {
1123+ return null ;
1124+ }
1125+ }
1126+ }
1127+
11051128 protected VIF createVif (Connection conn , String vmName , VM vm , VirtualMachineTO vmSpec , NicTO nic ) throws XmlRpcException , XenAPIException {
11061129 assert (nic .getUuid () != null ) : "Nic should have a uuid value" ;
11071130
@@ -1122,7 +1145,7 @@ protected VIF createVif(Connection conn, String vmName, VM vm, VirtualMachineTO
11221145 if (vmSpec != null ) {
11231146 vifr .otherConfig .put ("cloudstack-vm-id" , vmSpec .getUuid ());
11241147 }
1125-
1148+ vifr . otherConfig . put ( "cloudstack-network-id" , nic . getNetworkUuid ());
11261149 vifr .network = getNetwork (conn , nic );
11271150
11281151 if (nic .getNetworkRateMbps () != null && nic .getNetworkRateMbps ().intValue () != -1 ) {
@@ -5220,30 +5243,30 @@ protected boolean can_bridge_firewall(Connection conn) {
52205243
52215244 private Answer execute (OvsSetupBridgeCommand cmd ) {
52225245 Connection conn = getConnection ();
5223- findOrCreateTunnelNetwork (conn , cmd .getKey ());
5224- configureTunnelNetwork (conn , cmd .getNetworkId (), cmd .getHostId (), cmd .getKey ());
5246+ findOrCreateTunnelNetwork (conn , cmd .getBridgeName ());
5247+ configureTunnelNetwork (conn , cmd .getNetworkId (), cmd .getHostId (), cmd .getBridgeName ());
52255248 s_logger .debug ("OVS Bridge configured" );
52265249 return new Answer (cmd , true , null );
52275250 }
52285251
52295252 private Answer execute (OvsDestroyBridgeCommand cmd ) {
52305253 Connection conn = getConnection ();
5231- destroyTunnelNetwork (conn , cmd .getKey ());
5254+ destroyTunnelNetwork (conn , cmd .getBridgeName ());
52325255 s_logger .debug ("OVS Bridge destroyed" );
52335256 return new Answer (cmd , true , null );
52345257 }
52355258
52365259 private Answer execute (OvsDestroyTunnelCommand cmd ) {
52375260 Connection conn = getConnection ();
52385261 try {
5239- Network nw = findOrCreateTunnelNetwork (conn , cmd .getNetworkId ());
5262+ Network nw = findOrCreateTunnelNetwork (conn , cmd .getBridgeName ());
52405263 if (nw == null ) {
5241- s_logger .warn ("Unable to find tunnel network for GRE key:" + cmd .getKey ());
5264+ s_logger .warn ("Unable to find tunnel network for GRE key:" + cmd .getBridgeName ());
52425265 return new Answer (cmd , false , "No network found" );
52435266 }
52445267
52455268 String bridge = nw .getBridge (conn );
5246- String result = callHostPlugin (conn , "ovstunnel" , "destroy_tunnel " , "bridge" , bridge , "in_port" , cmd .getInPortName ());
5269+ String result = callHostPlugin (conn , "ovstunnel" , "configure_ovs_bridge_for_network_topology " , "bridge" , bridge , "in_port" , cmd .getInPortName ());
52475270 if (result .equalsIgnoreCase ("SUCCESS" )) {
52485271 return new Answer (cmd , true , result );
52495272 } else {
@@ -5255,6 +5278,22 @@ private Answer execute(OvsDestroyTunnelCommand cmd) {
52555278 }
52565279 }
52575280
5281+ public Answer execute (OvsVpcPhysicalTopologyConfigCommand cmd ) {
5282+ Connection conn = getConnection ();
5283+ try {
5284+ String result = callHostPlugin (conn , "ovstunnel" , "configure_ovs_bridge_for_network_topology" , "bridge" ,
5285+ cmd .getBridgeName (), "host-id" , ((Long )cmd .getHostId ()).toString ());
5286+ if (result .equalsIgnoreCase ("SUCCESS" )) {
5287+ return new Answer (cmd , true , result );
5288+ } else {
5289+ return new Answer (cmd , false , result );
5290+ }
5291+ } catch (Exception e ) {
5292+ s_logger .warn ("caught exception while updating host with latest VPC topology" , e );
5293+ return new Answer (cmd , false , e .getMessage ());
5294+ }
5295+ }
5296+
52585297 private Answer execute (UpdateHostPasswordCommand cmd ) {
52595298 _password .add (cmd .getNewPassword ());
52605299 return new Answer (cmd , true , null );
@@ -5264,17 +5303,19 @@ private OvsCreateTunnelAnswer execute(OvsCreateTunnelCommand cmd) {
52645303 Connection conn = getConnection ();
52655304 String bridge = "unknown" ;
52665305 try {
5267- Network nw = findOrCreateTunnelNetwork (conn , cmd .getKey ());
5306+ Network nw = findOrCreateTunnelNetwork (conn , cmd .getNetworkName ());
52685307 if (nw == null ) {
52695308 s_logger .debug ("Error during bridge setup" );
52705309 return new OvsCreateTunnelAnswer (cmd , false , "Cannot create network" , bridge );
52715310 }
52725311
5273- configureTunnelNetwork (conn , cmd .getNetworkId (), cmd .getFrom (), cmd .getKey ());
5312+ configureTunnelNetwork (conn , cmd .getNetworkId (), cmd .getFrom (), cmd .getNetworkName ());
52745313 bridge = nw .getBridge (conn );
52755314 String result =
5276- callHostPlugin (conn , "ovstunnel" , "create_tunnel" , "bridge" , bridge , "remote_ip" , cmd .getRemoteIp (), "key" , cmd .getKey ().toString (), "from" ,
5277- cmd .getFrom ().toString (), "to" , cmd .getTo ().toString ());
5315+ callHostPlugin (conn , "ovstunnel" , "create_tunnel" , "bridge" , bridge , "remote_ip" , cmd .getRemoteIp (),
5316+ "key" , cmd .getKey ().toString (), "from" ,
5317+ cmd .getFrom ().toString (), "to" , cmd .getTo ().toString (), "cloudstack-network-id" ,
5318+ cmd .getNetworkUuid ());
52785319 String [] res = result .split (":" );
52795320 if (res .length == 2 && res [0 ].equalsIgnoreCase ("SUCCESS" )) {
52805321 return new OvsCreateTunnelAnswer (cmd , true , result , res [1 ], bridge );
0 commit comments