Skip to content

Commit 2fc1dc0

Browse files
committed
VPC : vpc integration code for XenServer hypervisor
1 parent d5d6c9f commit 2fc1dc0

4 files changed

Lines changed: 510 additions & 69 deletions

File tree

api/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17+
1718
package com.cloud.agent.api.routing;
1819

20+
import java.util.HashSet;
1921
import java.util.List;
22+
import java.util.Set;
2023

2124
import com.cloud.agent.api.to.NetworkACLTO;
2225
import com.cloud.agent.api.to.NicTO;
2326

27+
/**
28+
* @author Alena Prokharchyk
29+
*/
2430
public class SetNetworkACLCommand extends NetworkElementCommand{
2531
NetworkACLTO[] rules;
2632
NicTO nic;
@@ -36,6 +42,57 @@ public SetNetworkACLCommand(List<NetworkACLTO> rules, NicTO nic) {
3642
public NetworkACLTO[] getRules() {
3743
return rules;
3844
}
45+
public String[][] generateFwRules() {
46+
String [][] result = new String [2][];
47+
Set<String> toAdd = new HashSet<String>();
48+
49+
50+
for (NetworkACLTO aclTO: rules) {
51+
/* example : Ingress:tcp:80:80:0.0.0.0/0:,Egress:tcp:220:220:0.0.0.0/0:,
52+
* each entry format Ingress/Egress:protocol:start port: end port:scidrs:
53+
* reverted entry format Ingress/Egress:reverted:0:0:0:
54+
*/
55+
if (aclTO.revoked() == true)
56+
{
57+
StringBuilder sb = new StringBuilder();
58+
/* This entry is added just to make sure atleast there will one entry in the list to get the ipaddress */
59+
sb.append(aclTO.getTrafficType().toString()).append(":reverted:0:0:0:");
60+
String aclRuleEntry = sb.toString();
61+
toAdd.add(aclRuleEntry);
62+
continue;
63+
}
64+
65+
List<String> cidr;
66+
StringBuilder sb = new StringBuilder();
67+
sb.append(aclTO.getTrafficType().toString()).append(":").append(aclTO.getProtocol()).append(":");
68+
if ("icmp".compareTo(aclTO.getProtocol()) == 0)
69+
{
70+
sb.append(aclTO.getIcmpType()).append(":").append(aclTO.getIcmpCode()).append(":");
71+
} else {
72+
sb.append(aclTO.getStringPortRange()).append(":");
73+
}
74+
cidr = aclTO.getSourceCidrList();
75+
if (cidr == null || cidr.isEmpty())
76+
{
77+
sb.append("0.0.0.0/0");
78+
}else{
79+
Boolean firstEntry = true;
80+
for (String tag : cidr) {
81+
if (!firstEntry) sb.append("-");
82+
sb.append(tag);
83+
firstEntry = false;
84+
}
85+
}
86+
sb.append(":");
87+
String aclRuleEntry = sb.toString();
88+
89+
toAdd.add(aclRuleEntry);
90+
91+
}
92+
result[0] = toAdd.toArray(new String[toAdd.size()]);
93+
94+
return result;
95+
}
3996

4097
public NicTO getNic() {
4198
return nic;

api/src/com/cloud/agent/api/SetSourceNatAnswer.java renamed to api/src/com/cloud/agent/api/routing/SetSourceNatAnswer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
// under the License.
1717
package com.cloud.agent.api;
1818

19+
import com.cloud.agent.api.routing.SetSourceNatCommand;
20+
1921
public class SetSourceNatAnswer extends Answer{
2022
public SetSourceNatAnswer() {}
2123

22-
public SetSourceNatAnswer(PlugNicCommand cmd, boolean success, String result) {
24+
public SetSourceNatAnswer(SetSourceNatCommand cmd, boolean success, String result) {
2325
super(cmd, success, result);
2426
}
2527
}

api/src/com/cloud/agent/api/routing/SetStaticRouteCommand.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17+
1718
package com.cloud.agent.api.routing;
1819

20+
import java.util.HashSet;
1921
import java.util.List;
22+
import java.util.Set;
2023

24+
import com.cloud.network.vpc.StaticRoute;
2125
import com.cloud.network.vpc.StaticRouteProfile;
26+
import com.cloud.utils.net.NetUtils;
2227

28+
/**
29+
* @author Alena Prokharchyk
30+
*/
2331
public class SetStaticRouteCommand extends NetworkElementCommand{
2432
StaticRouteProfile[] staticRoutes;
2533

@@ -33,4 +41,28 @@ public SetStaticRouteCommand(List<StaticRouteProfile> staticRoutes) {
3341
public StaticRouteProfile[] getStaticRoutes() {
3442
return staticRoutes;
3543
}
44+
45+
public boolean isEmpty() {
46+
if(staticRoutes == null || staticRoutes.length == 0 ) {
47+
return true;
48+
}
49+
return false;
50+
}
51+
public String[][] generateSRouteRules() {
52+
String [][] result = new String [2][];
53+
Set<String> toAdd = new HashSet<String>();
54+
for (StaticRouteProfile route: staticRoutes) {
55+
/* example : ip:gateway:cidr,
56+
*/
57+
if( route.getState() == StaticRoute.State.Active || route.getState() == StaticRoute.State.Add ) {
58+
String cidr = route.getCidr();
59+
String subnet = NetUtils.getCidrSubNet(cidr);
60+
String cidrSize = cidr.split("\\/")[1];
61+
String entry = route.getIp4Address()+ ":" + route.getGateway() + ":" + subnet + "/" + cidrSize;
62+
toAdd.add(entry);
63+
}
64+
}
65+
result[0] = toAdd.toArray(new String[toAdd.size()]);
66+
return result;
67+
}
3668
}

0 commit comments

Comments
 (0)