@@ -901,22 +901,31 @@ func ConfigTunnelDecapTunnelTypePost(w http.ResponseWriter, r *http.Request) {
901
901
return
902
902
}
903
903
904
- kv , err := GetKVs (db .db_num , generateDBTableKey (db .separator , VXLAN_TUNNEL_TB , "default_vxlan_tunnel" ))
904
+ tunnel_name := "default_vxlan_tunnel"
905
+ // Check if IP address is V4.
906
+ if IsValidIP (attr .IPAddr ) {
907
+ tunnel_name = "default_vxlan_tunnel_v4"
908
+ }
909
+
910
+ kv , err := GetKVs (db .db_num , generateDBTableKey (db .separator , VXLAN_TUNNEL_TB , tunnel_name ))
905
911
if err != nil {
906
912
WriteRequestError (w , http .StatusInternalServerError , "Internal service error" , []string {}, "" )
907
913
return
908
914
}
909
915
916
+ //Check if tunnel already exist and the address family is same
910
917
if kv != nil {
911
- WriteRequestErrorWithSubCode (w , http .StatusConflict , RESRC_EXISTS ,
912
- "Object already exists: Default Vxlan VTEP" , []string {}, "" )
913
- return
918
+ if isV4orV6 (kv ["src_ip" ]) == isV4orV6 (attr .IPAddr ) {
919
+ WriteRequestErrorWithSubCode (w , http .StatusConflict , RESRC_EXISTS ,
920
+ "Object already exists: Default Vxlan VTEP" , []string {}, "" )
921
+ return
922
+ }
914
923
}
915
924
916
925
pt := swsscommon .NewTable (db .swss_db , VXLAN_TUNNEL_TB )
917
926
defer pt .Delete ()
918
927
919
- pt .Set ("default_vxlan_tunnel" , map [string ]string {
928
+ pt .Set (tunnel_name , map [string ]string {
920
929
"src_ip" : attr .IPAddr ,
921
930
}, "SET" , "" )
922
931
@@ -1025,18 +1034,36 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) {
1025
1034
return
1026
1035
}
1027
1036
1028
- kv , err := GetKVs (db .db_num , generateDBTableKey (db .separator , VXLAN_TUNNEL_TB , "default_vxlan_tunnel" ))
1037
+ tunnel_name := "default_vxlan_tunnel_v4"
1038
+ kv_4 , err := GetKVs (db .db_num , generateDBTableKey (db .separator , VXLAN_TUNNEL_TB , tunnel_name ))
1029
1039
if err != nil {
1030
1040
WriteRequestError (w , http .StatusInternalServerError , "Internal service error" , []string {}, "" )
1031
1041
return
1032
1042
}
1033
1043
1034
- if kv == nil {
1044
+ tunnel_name = "default_vxlan_tunnel"
1045
+ kv , err := GetKVs (db .db_num , generateDBTableKey (db .separator , VXLAN_TUNNEL_TB , tunnel_name ))
1046
+ if err != nil {
1047
+ WriteRequestError (w , http .StatusInternalServerError , "Internal service error" , []string {}, "" )
1048
+ return
1049
+ }
1050
+
1051
+ if kv == nil && kv_4 == nil {
1035
1052
WriteRequestErrorWithSubCode (w , http .StatusConflict , DEP_MISSING ,
1036
1053
"Default VxLAN VTEP must be created prior to creating VRF" , []string {"tunnel" }, "" )
1037
1054
return
1038
1055
}
1039
1056
1057
+ var v6_tunnel , v4_tunnel bool
1058
+ if kv_4 != nil {
1059
+ tunnel_name = "default_vxlan_tunnel_v4"
1060
+ v4_tunnel = true
1061
+ }
1062
+ if kv != nil {
1063
+ tunnel_name = "default_vxlan_tunnel"
1064
+ v6_tunnel = true
1065
+ }
1066
+
1040
1067
vnet_id := CacheGetVnetGuidId (vars ["vnet_name" ])
1041
1068
if vnet_id != 0 {
1042
1069
WriteRequestErrorWithSubCode (w , http .StatusConflict , RESRC_EXISTS ,
@@ -1046,9 +1073,12 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) {
1046
1073
1047
1074
guid := CacheGetVniId (uint32 (attr .Vnid ))
1048
1075
if guid != "" {
1049
- WriteRequestErrorWithSubCode (w , http .StatusConflict , RESRC_EXISTS ,
1050
- "Object already exists: {\" vni\" :\" " + strconv .Itoa (attr .Vnid ) + "\" , \" vnet_name\" :\" " + guid + "\" }" , []string {}, "" )
1051
- return
1076
+ // Default Vnets can have same Vnid
1077
+ if ! (strings .Contains (guid , "Vnet-default" )) {
1078
+ WriteRequestErrorWithSubCode (w , http .StatusConflict , RESRC_EXISTS ,
1079
+ "Object already exists: {\" vni\" :\" " + strconv .Itoa (attr .Vnid ) + "\" , \" vnet_name\" :\" " + guid + "\" }" , []string {}, "" )
1080
+ return
1081
+ }
1052
1082
}
1053
1083
1054
1084
vnet_id = CacheGenAndSetVnetGuidId (vars ["vnet_name" ], uint32 (attr .Vnid ))
@@ -1070,11 +1100,23 @@ func ConfigVrouterVrfIdPost(w http.ResponseWriter, r *http.Request) {
1070
1100
1071
1101
log .Printf ("debug: vnet_id_str: " + vnet_id_str )
1072
1102
vnetParams := make (map [string ]string )
1073
- vnetParams ["vxlan_tunnel" ] = "default_vxlan_tunnel"
1103
+ vnetParams ["vxlan_tunnel" ] = tunnel_name
1074
1104
vnetParams ["vni" ] = strconv .Itoa (attr .Vnid )
1075
1105
vnetParams ["guid" ] = vars ["vnet_name" ]
1076
1106
if strings .Compare (vars ["vnet_name" ], "Vnet-default" ) == 0 {
1107
+ if v6_tunnel == false {
1108
+ WriteRequestError (w , http .StatusInternalServerError , "Vnet-default is for V6 Tunnels, please create Vnet-default-v4" , []string {}, "" )
1109
+ return
1110
+ }
1111
+ vnetParams ["scope" ] = "default"
1112
+ vnetParams ["vxlan_tunnel" ] = "default_vxlan_tunnel"
1113
+ } else if strings .Compare (vars ["vnet_name" ], "Vnet-default-v4" ) == 0 {
1114
+ if v4_tunnel == false {
1115
+ WriteRequestError (w , http .StatusInternalServerError , "V4 tunnel not created, please create V4 Vxlan Tunnel" , []string {}, "" )
1116
+ return
1117
+ }
1077
1118
vnetParams ["scope" ] = "default"
1119
+ vnetParams ["vxlan_tunnel" ] = "default_vxlan_tunnel_v4"
1078
1120
}
1079
1121
if attr .AdvPrefix != "" {
1080
1122
vnetParams ["advertise_prefix" ] = attr .AdvPrefix
0 commit comments