Search in sources :

Example 1 with InterfaceConfig

use of org.onosproject.net.config.basics.InterfaceConfig in project onos by opennetworkinglab.

the class InterfaceManager method remove.

@Override
public boolean remove(ConnectPoint connectPoint, String name) {
    InterfaceConfig config = configService.addConfig(connectPoint, CONFIG_CLASS);
    config.removeInterface(name);
    try {
        if (config.getInterfaces().isEmpty()) {
            configService.removeConfig(connectPoint, CONFIG_CLASS);
        } else {
            configService.applyConfig(connectPoint, CONFIG_CLASS, config.node());
        }
    } catch (ConfigException e) {
        log.error("Error reading interfaces JSON", e);
        return false;
    }
    return true;
}
Also used : InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) ConfigException(org.onosproject.net.config.ConfigException)

Example 2 with InterfaceConfig

use of org.onosproject.net.config.basics.InterfaceConfig in project onos by opennetworkinglab.

the class InterfaceManagerTest method testUpdateInterface.

@Test
public void testUpdateInterface() throws Exception {
    ConnectPoint cp = createConnectPoint(1);
    // Create an interface that is the same as the existing one, but adds a
    // new IP address
    Interface intf = createInterface(1);
    List<InterfaceIpAddress> addresses = Lists.newArrayList(intf.ipAddressesList());
    addresses.add(InterfaceIpAddress.valueOf("192.168.100.1/24"));
    intf = new Interface(Interface.NO_INTERFACE_NAME, intf.connectPoint(), addresses, intf.mac(), intf.vlan());
    // Create a new interface on the same connect point as the existing one
    InterfaceIpAddress newAddr = InterfaceIpAddress.valueOf("192.168.101.1/24");
    Interface newIntf = new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.singletonList(newAddr), MacAddress.valueOf(101), VlanId.vlanId((short) 101));
    Set<Interface> interfaces = Sets.newHashSet(intf, newIntf);
    // New interface config updates the existing interface and adds a new
    // interface to the same connect point
    InterfaceConfig oldIc = new TestInterfaceConfig(cp, Sets.newHashSet(intf));
    InterfaceConfig ic = new TestInterfaceConfig(cp, interfaces);
    configs.put(cp, ic);
    NetworkConfigEvent event = new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_UPDATED, cp, ic, oldIc, CONFIG_CLASS);
    // Send in the event signalling the interfaces for this connect point
    // have been updated
    listener.event(event);
    assertEquals(NUM_INTERFACES + 1, interfaceManager.getInterfaces().size());
    assertEquals(interfaces, interfaceManager.getInterfacesByPort(cp));
}
Also used : InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Test(org.junit.Test)

Example 3 with InterfaceConfig

use of org.onosproject.net.config.basics.InterfaceConfig in project onos by opennetworkinglab.

the class InterfaceManagerTest method testAddInterface.

@Test
public void testAddInterface() throws Exception {
    // Create a new InterfaceConfig which will get added
    VlanId vlanId = VlanId.vlanId((short) 1);
    ConnectPoint cp = ConnectPoint.deviceConnectPoint("of:0000000000000001/2");
    Interface newIntf = new Interface(Interface.NO_INTERFACE_NAME, cp, Collections.emptyList(), MacAddress.valueOf(100), vlanId);
    InterfaceConfig ic = new TestInterfaceConfig(cp, Collections.singleton(newIntf));
    subjects.add(cp);
    configs.put(cp, ic);
    interfaces.add(newIntf);
    NetworkConfigEvent event = new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, cp, ic, null, CONFIG_CLASS);
    assertEquals(NUM_INTERFACES, interfaceManager.getInterfaces().size());
    // Send in a config event containing a new interface config
    listener.event(event);
    // Check the new interface exists in the InterfaceManager's inventory
    assertEquals(interfaces, interfaceManager.getInterfaces());
    assertEquals(NUM_INTERFACES + 1, interfaceManager.getInterfaces().size());
    // There are now two interfaces with vlan ID 1
    Set<Interface> byVlan = Sets.newHashSet(createInterface(1), newIntf);
    assertEquals(byVlan, interfaceManager.getInterfacesByVlan(vlanId));
}
Also used : InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) ConnectPoint(org.onosproject.net.ConnectPoint) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface) Test(org.junit.Test)

Example 4 with InterfaceConfig

use of org.onosproject.net.config.basics.InterfaceConfig in project onos by opennetworkinglab.

the class InterfaceManager method add.

@Override
public void add(Interface intf) {
    InterfaceConfig config = configService.addConfig(intf.connectPoint(), CONFIG_CLASS);
    config.addInterface(intf);
    configService.applyConfig(intf.connectPoint(), CONFIG_CLASS, config.node());
}
Also used : InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig)

Example 5 with InterfaceConfig

use of org.onosproject.net.config.basics.InterfaceConfig in project onos by opennetworkinglab.

the class InterfaceManager method activate.

@Activate
public void activate() {
    configService.addListener(listener);
    // TODO address concurrency issues here
    for (ConnectPoint subject : configService.getSubjects(SUBJECT_CLASS, CONFIG_CLASS)) {
        InterfaceConfig config = configService.getConfig(subject, CONFIG_CLASS);
        if (config != null) {
            updateInterfaces(config);
        }
    }
    log.info("Started");
}
Also used : InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) ConnectPoint(org.onosproject.net.ConnectPoint) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

InterfaceConfig (org.onosproject.net.config.basics.InterfaceConfig)6 ConnectPoint (org.onosproject.net.ConnectPoint)4 Interface (org.onosproject.net.intf.Interface)3 Test (org.junit.Test)2 NetworkConfigEvent (org.onosproject.net.config.NetworkConfigEvent)2 Before (org.junit.Before)1 VlanId (org.onlab.packet.VlanId)1 ConfigException (org.onosproject.net.config.ConfigException)1 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)1 Activate (org.osgi.service.component.annotations.Activate)1