Search in sources :

Example 86 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final StaticNatRules nat) throws ResourceUnavailableException {
    final Network network = nat.getNetwork();
    final VirtualRouter router = nat.getRouter();
    final List<? extends StaticNat> rules = nat.getRules();
    final Commands cmds = new Commands(Command.OnError.Continue);
    _commandSetupHelper.createApplyStaticNatCommands(rules, router, cmds, network.getId());
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 87 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final DhcpSubNetRules subnet) throws ResourceUnavailableException {
    final VirtualRouter router = subnet.getRouter();
    final Network network = subnet.getNetwork();
    final NicIpAliasVO nicAlias = subnet.getNicAlias();
    final String routerAliasIp = subnet.getRouterAliasIp();
    final Commands cmds = new Commands(Command.OnError.Stop);
    final List<IpAliasTO> ipaliasTo = new ArrayList<IpAliasTO>();
    ipaliasTo.add(new IpAliasTO(routerAliasIp, nicAlias.getNetmask(), nicAlias.getAliasCount().toString()));
    _commandSetupHelper.createIpAlias(router, ipaliasTo, nicAlias.getNetworkId(), cmds);
    // also add the required configuration to the dnsmasq for supporting
    // dhcp and dns on the new ip.
    _commandSetupHelper.configDnsMasq(router, network, cmds);
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) ArrayList(java.util.ArrayList) IpAliasTO(com.cloud.agent.api.routing.IpAliasTO) NicIpAliasVO(com.cloud.vm.dao.NicIpAliasVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 88 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class CreateNetworkOfferingTest method createVpcNtwkOff.

@Test
public void createVpcNtwkOff() {
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
    Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
    vrProvider.add(Provider.VPCVirtualRouter);
    serviceProviderMap.put(Network.Service.Dhcp, vrProvider);
    serviceProviderMap.put(Network.Service.Dns, vrProvider);
    serviceProviderMap.put(Network.Service.Lb, vrProvider);
    serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
    serviceProviderMap.put(Network.Service.Gateway, vrProvider);
    serviceProviderMap.put(Network.Service.Lb, vrProvider);
    NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, true, Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true);
    // System.out.println("Creating Vpc Network Offering");
    assertNotNull("Vpc Isolated network offering with Vpc provider ", off);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Network(com.cloud.network.Network) Service(com.cloud.network.Network.Service) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 89 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class NetworkACLManagerTest method driveTestApplyNetworkACL.

@SuppressWarnings("unchecked")
public void driveTestApplyNetworkACL(final boolean result, final boolean applyNetworkACLs, final boolean applyACLToPrivateGw) throws Exception {
    // In order to test ONLY our scope method, we mock the others
    final NetworkACLManager aclManager = Mockito.spy(_aclMgr);
    // Prepare
    // Reset mocked objects to reuse
    Mockito.reset(_networkACLItemDao);
    // Make sure it is handled
    final long aclId = 1L;
    final NetworkVO network = Mockito.mock(NetworkVO.class);
    final List<NetworkVO> networks = new ArrayList<NetworkVO>();
    networks.add(network);
    Mockito.when(_networkDao.listByAclId(Matchers.anyLong())).thenReturn(networks);
    Mockito.when(_networkDao.findById(Matchers.anyLong())).thenReturn(network);
    Mockito.when(_networkModel.isProviderSupportServiceInNetwork(Matchers.anyLong(), Matchers.any(Network.Service.class), Matchers.any(Network.Provider.class))).thenReturn(true);
    Mockito.when(_networkAclElements.get(0).applyNetworkACLs(Matchers.any(Network.class), Matchers.anyList())).thenReturn(applyNetworkACLs);
    // Make sure it applies ACL to private gateway
    final List<VpcGatewayVO> vpcGateways = new ArrayList<VpcGatewayVO>();
    final VpcGatewayVO vpcGateway = Mockito.mock(VpcGatewayVO.class);
    final PrivateGateway privateGateway = Mockito.mock(PrivateGateway.class);
    Mockito.when(_vpcSvc.getVpcPrivateGateway(Mockito.anyLong())).thenReturn(privateGateway);
    vpcGateways.add(vpcGateway);
    Mockito.when(_vpcGatewayDao.listByAclIdAndType(aclId, VpcGateway.Type.Private)).thenReturn(vpcGateways);
    // Create 4 rules to test all 4 scenarios: only revoke should
    // be deleted, only add should update
    final List<NetworkACLItemVO> rules = new ArrayList<NetworkACLItemVO>();
    final NetworkACLItemVO ruleActive = Mockito.mock(NetworkACLItemVO.class);
    final NetworkACLItemVO ruleStaged = Mockito.mock(NetworkACLItemVO.class);
    final NetworkACLItemVO rule2Revoke = Mockito.mock(NetworkACLItemVO.class);
    final NetworkACLItemVO rule2Add = Mockito.mock(NetworkACLItemVO.class);
    Mockito.when(ruleActive.getState()).thenReturn(NetworkACLItem.State.Active);
    Mockito.when(ruleStaged.getState()).thenReturn(NetworkACLItem.State.Staged);
    Mockito.when(rule2Add.getState()).thenReturn(NetworkACLItem.State.Add);
    Mockito.when(rule2Revoke.getState()).thenReturn(NetworkACLItem.State.Revoke);
    rules.add(ruleActive);
    rules.add(ruleStaged);
    rules.add(rule2Add);
    rules.add(rule2Revoke);
    final long revokeId = 8;
    Mockito.when(rule2Revoke.getId()).thenReturn(revokeId);
    final long addId = 9;
    Mockito.when(rule2Add.getId()).thenReturn(addId);
    Mockito.when(_networkACLItemDao.findById(addId)).thenReturn(rule2Add);
    Mockito.when(_networkACLItemDao.listByACL(aclId)).thenReturn(rules);
    // Mock methods to avoid
    Mockito.doReturn(applyACLToPrivateGw).when(aclManager).applyACLToPrivateGw(privateGateway);
    // Execute
    assertEquals("Result was not congruent with applyNetworkACLs and applyACLToPrivateGw", result, aclManager.applyNetworkACL(aclId));
    // Assert if conditions met, network ACL was applied
    final int timesProcessingDone = applyNetworkACLs && applyACLToPrivateGw ? 1 : 0;
    Mockito.verify(_networkACLItemDao, Mockito.times(timesProcessingDone)).remove(revokeId);
    Mockito.verify(rule2Add, Mockito.times(timesProcessingDone)).setState(NetworkACLItem.State.Active);
    Mockito.verify(_networkACLItemDao, Mockito.times(timesProcessingDone)).update(addId, rule2Add);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) VpcService(com.cloud.network.vpc.VpcService) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NetworkACLManager(com.cloud.network.vpc.NetworkACLManager) NetworkACLServiceProvider(com.cloud.network.element.NetworkACLServiceProvider) PrivateGateway(com.cloud.network.vpc.PrivateGateway) Network(com.cloud.network.Network)

Example 90 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class CreateNetworkOfferingTest method createIsolatedNtwkOffWithNoVlan.

//Test Isolated network offerings
@Test
public void createIsolatedNtwkOffWithNoVlan() {
    Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
    Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
    vrProvider.add(Provider.VirtualRouter);
    serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
    NetworkOfferingVO off = configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false, Availability.Optional, 200, serviceProviderMap, false, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true);
    assertNotNull("Isolated network offering with specifyIpRanges=false failed to create ", off);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Network(com.cloud.network.Network) Service(com.cloud.network.Network.Service) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Provider(com.cloud.network.Network.Provider) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Network (com.cloud.network.Network)235 ArrayList (java.util.ArrayList)86 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)63 Account (com.cloud.user.Account)60 Test (org.junit.Test)55 NetworkOffering (com.cloud.offering.NetworkOffering)52 PhysicalNetwork (com.cloud.network.PhysicalNetwork)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)50 NetworkVO (com.cloud.network.dao.NetworkVO)38 DataCenter (com.cloud.dc.DataCenter)34 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 NicProfile (com.cloud.vm.NicProfile)31 HostVO (com.cloud.host.HostVO)27 DB (com.cloud.utils.db.DB)27 List (java.util.List)27 DataCenterVO (com.cloud.dc.DataCenterVO)26 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 HashMap (java.util.HashMap)24 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)23 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20