public SetNetworkACLAnswer(SetNetworkACLCommand cmd, boolean success, String[] results) { super(cmd, success, null); assert (cmd.getRules().length == results.length) : "ACLs and their results should be the same length"; this.results = results; }
private ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand cmd) { final NicTO nic = cmd.getNic(); final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final URI broadcastUri = nic.getBroadcastUri(); final String vlanId = BroadcastDomainType.getValue(broadcastUri); final int ethDeviceNum = getVmNics(routerName, vlanId); if (ethDeviceNum > 0) { nic.setDeviceId(ethDeviceNum); } else { return new ExecutionResult(false, "Prepare SetNetworkACL failed due to unable to find the nic"); } } catch (final Exception e) { final String msg = "Prepare SetNetworkACL failed due to " + e.toString(); s_logger.error(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); }
final String[][] rules = command.generateFwRules(); final String[] aclRules = rules[0]; final NicTO nic = command.getNic(); final String dev = "eth" + nic.getDeviceId(); final String netmask = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
public void createNetworkACLsCommands(final List<? extends NetworkACLItem> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId, final boolean privateGateway) { final List<NetworkACLTO> rulesTO = new ArrayList<NetworkACLTO>(); String guestVlan = null; final Network guestNtwk = _networkDao.findById(guestNetworkId); final URI uri = guestNtwk.getBroadcastUri(); if (uri != null) { guestVlan = BroadcastDomainType.getValue(uri); } if (rules != null) { for (final NetworkACLItem rule : rules) { final NetworkACLTO ruleTO = new NetworkACLTO(rule, guestVlan, rule.getTrafficType()); rulesTO.add(ruleTO); } } NicTO nicTO = _networkHelper.getNicTO(router, guestNetworkId, null); final SetNetworkACLCommand cmd = new SetNetworkACLCommand(rulesTO, nicTO); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId())); cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, guestVlan); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); if (privateGateway) { cmd.setAccessDetail(NetworkElementCommand.VPC_PRIVATE_GATEWAY, String.valueOf(VpcGateway.Type.Private)); } cmds.addCommand(cmd); }
public String[][] generateFwRules() { final List<NetworkACLTO> aclList = Arrays.asList(rules); orderNetworkAclRulesByRuleNumber(aclList);
protected ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand cmd) { final Connection conn = getConnection(); final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); try { final VM router = getVM(conn, routerName); final NicTO nic = cmd.getNic(); if (nic != null) { final VIF vif = getVifByMac(conn, router, nic.getMac()); if (vif == null) { final String msg = "Prepare SetNetworkACL failed due to VIF is null for : " + nic.getMac() + " with routername: " + routerName; s_logger.error(msg); return new ExecutionResult(false, msg); } nic.setDeviceId(Integer.parseInt(vif.getDevice(conn))); } else { final String msg = "Prepare SetNetworkACL failed due to nic is null for : " + routerName; s_logger.error(msg); return new ExecutionResult(false, msg); } } catch (final Exception e) { final String msg = "Prepare SetNetworkACL failed due to " + e.toString(); s_logger.error(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); }