Search in sources :

Example 1 with VirtualNetworkIntent

use of org.onosproject.incubator.net.virtual.VirtualNetworkIntent in project onos by opennetworkinglab.

the class VirtualNetworkIntentManagerTest method testGetIntents.

/**
 * Tests the getIntents, getIntent(), getIntentData(), getIntentCount(),
 * isLocal() methods.
 */
@Test
public void testGetIntents() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    Key intentKey = Key.of("test", APP_ID);
    List<Constraint> constraints = new ArrayList<>();
    constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
    VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(intentKey).appId(APP_ID).ingressPoint(cp1).egressPoint(cp5).constraints(constraints).build();
    // Test the submit() method.
    vnetIntentService.submit(virtualIntent);
    // Wait for the both intents to go into an INSTALLED state.
    try {
        if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get installed.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent installation." + e.getMessage());
    }
    // Test the getIntents() method
    assertEquals("The intents size did not match as expected.", 1, Iterators.size(vnetIntentService.getIntents().iterator()));
    // Test the getIntent() method
    assertNotNull("The intent should have been found.", vnetIntentService.getIntent(virtualIntent.key()));
    // Test the getIntentData() method
    assertEquals("The intent data size did not match as expected.", 1, Iterators.size(vnetIntentService.getIntentData().iterator()));
    // Test the getIntentCount() method
    assertEquals("The intent count did not match as expected.", 1, vnetIntentService.getIntentCount());
    // Test the isLocal() method
    assertTrue("The intent should be local.", vnetIntentService.isLocal(virtualIntent.key()));
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Key(org.onosproject.net.intent.Key) Test(org.junit.Test)

Example 2 with VirtualNetworkIntent

use of org.onosproject.incubator.net.virtual.VirtualNetworkIntent in project onos by opennetworkinglab.

the class VirtualNetworkIntentManager method submit.

@Override
public void submit(Intent intent) {
    checkNotNull(intent, INTENT_NULL);
    checkState(intent instanceof VirtualNetworkIntent, "Only VirtualNetworkIntent is supported.");
    checkArgument(validateIntent((VirtualNetworkIntent) intent), "Invalid Intent");
    IntentData data = IntentData.submit(intent);
    intentStore.addPending(networkId, data);
}
Also used : VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) IntentData(org.onosproject.net.intent.IntentData)

Example 3 with VirtualNetworkIntent

use of org.onosproject.incubator.net.virtual.VirtualNetworkIntent in project onos by opennetworkinglab.

the class VirtualNetworkIntentManagerTest method testCreateAndRemoveIntent.

/**
 * Tests the submit(), withdraw(), and purge() methods.
 */
@Test
public void testCreateAndRemoveIntent() {
    VirtualNetwork virtualNetwork = setupVirtualNetworkTopology();
    Key intentKey = Key.of("test", APP_ID);
    List<Constraint> constraints = new ArrayList<>();
    constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
    VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(intentKey).appId(APP_ID).ingressPoint(cp1).egressPoint(cp5).constraints(constraints).build();
    // Test the submit() method.
    vnetIntentService.submit(virtualIntent);
    // Wait for the both intents to go into an INSTALLED state.
    try {
        if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get installed.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent installation." + e.getMessage());
    }
    // Test the getIntentState() method
    assertEquals("The intent state did not match as expected.", IntentState.INSTALLED, vnetIntentService.getIntentState(virtualIntent.key()));
    // Test the withdraw() method.
    vnetIntentService.withdraw(virtualIntent);
    // Wait for the both intents to go into a WITHDRAWN state.
    try {
        if (!withdrawn.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get withdrawn.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent withdrawal." + e.getMessage());
    }
    // Test the getIntentState() method
    assertEquals("The intent state did not match as expected.", IntentState.WITHDRAWN, vnetIntentService.getIntentState(virtualIntent.key()));
    // Test the purge() method.
    vnetIntentService.purge(virtualIntent);
    // Wait for the both intents to be removed/purged.
    try {
        if (!purged.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) {
            fail("Failed to wait for intent to get purged.");
        }
    } catch (InterruptedException e) {
        fail("Semaphore exception during intent purging." + e.getMessage());
    }
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Constraint(org.onosproject.net.intent.Constraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) Key(org.onosproject.net.intent.Key) Test(org.junit.Test)

Example 4 with VirtualNetworkIntent

use of org.onosproject.incubator.net.virtual.VirtualNetworkIntent in project onos by opennetworkinglab.

the class VirtualNetworkManagerTest method testAddTunnelId.

/**
 * Tests the addTunnelId, getTunnelIds(), removeTunnelId() methods with the store.
 */
@Test
public void testAddTunnelId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    ConnectPoint cp1 = new ConnectPoint(DID1, P1);
    ConnectPoint cp2 = new ConnectPoint(DID2, P1);
    VirtualNetworkIntent virtualIntent = VirtualNetworkIntent.builder().networkId(virtualNetwork.id()).key(Key.of("Test", APP_ID)).appId(APP_ID).ingressPoint(cp1).egressPoint(cp2).build();
    TunnelId tunnelId = TunnelId.valueOf("virtual tunnel");
    // Add the intent to tunnelID mapping to the store.
    manager.store.addTunnelId(virtualIntent, tunnelId);
    assertEquals("The tunnels size should match.", 1, manager.store.getTunnelIds(virtualIntent).size());
    // Remove the intent to tunnelID mapping from the store.
    manager.store.removeTunnelId(virtualIntent, tunnelId);
    assertTrue("The tunnels should be empty.", manager.store.getTunnelIds(virtualIntent).isEmpty());
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualNetworkIntent(org.onosproject.incubator.net.virtual.VirtualNetworkIntent) ConnectPoint(org.onosproject.net.ConnectPoint) TunnelId(org.onosproject.incubator.net.tunnel.TunnelId) Test(org.junit.Test)

Aggregations

VirtualNetworkIntent (org.onosproject.incubator.net.virtual.VirtualNetworkIntent)4 Test (org.junit.Test)3 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)3 ArrayList (java.util.ArrayList)2 Constraint (org.onosproject.net.intent.Constraint)2 Key (org.onosproject.net.intent.Key)2 EncapsulationConstraint (org.onosproject.net.intent.constraint.EncapsulationConstraint)2 TunnelId (org.onosproject.incubator.net.tunnel.TunnelId)1 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 IntentData (org.onosproject.net.intent.IntentData)1