Mahesh Poojary Huawei
Committed by Gerrit Code Review

[ONOS-4164] PceManager device and link event handling

Change-Id: I55d8f60e0fcc0e23f4c14045a8e20bd89f635913
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.util;
import java.util.Set;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.link.LinkListener;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.Link.State;
import com.google.common.collect.FluentIterable;
/**
* Test adapter for link service.
*/
public class LinkServiceAdapter implements LinkService {
@Override
public int getLinkCount() {
return 0;
}
@Override
public Iterable<Link> getLinks() {
return null;
}
@Override
public Iterable<Link> getActiveLinks() {
return FluentIterable.from(getLinks())
.filter(input -> input.state() == State.ACTIVE);
}
@Override
public Set<Link> getDeviceLinks(DeviceId deviceId) {
return null;
}
@Override
public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
return null;
}
@Override
public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
return null;
}
@Override
public Set<Link> getLinks(ConnectPoint connectPoint) {
return null;
}
@Override
public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
return null;
}
@Override
public Set<Link> getIngressLinks(ConnectPoint connectPoint) {
return null;
}
@Override
public Link getLink(ConnectPoint src, ConnectPoint dst) {
return null;
}
@Override
public void addListener(LinkListener listener) {
}
@Override
public void removeListener(LinkListener listener) {
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.util;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
/**
* Test fixture for the device service.
*/
public class MockDeviceService extends DeviceServiceAdapter {
private List<Device> devices = new LinkedList<>();
private DeviceListener listener;
public void addDevice(Device dev) {
devices.add(dev);
}
public void removeDevice(Device dev) {
devices.remove(dev);
}
@Override
public Device getDevice(DeviceId deviceId) {
for (Device dev : devices) {
if (dev.id().equals(deviceId)) {
return dev;
}
}
return null;
}
@Override
public Iterable<Device> getAvailableDevices() {
return devices;
}
@Override
public void addListener(DeviceListener listener) {
this.listener = listener;
}
/**
* Get the listener.
*/
public DeviceListener getListener() {
return listener;
}
}
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.pce.util;
import org.onosproject.net.Link;
import org.onosproject.net.link.LinkServiceAdapter;
import org.onosproject.net.link.LinkListener;
import java.util.ArrayList;
import java.util.List;
/**
* Test fixture for the link service.
*/
public class MockLinkService extends LinkServiceAdapter {
List<Link> links = new ArrayList<>();
LinkListener listener;
@Override
public int getLinkCount() {
return links.size();
}
@Override
public Iterable<Link> getLinks() {
return links;
}
@Override
public void addListener(LinkListener listener) {
this.listener = listener;
}
/**
* Get listener.
*/
public LinkListener getListener() {
return listener;
}
/**
* Add link.
*
* @param link needs to be added to list
*/
public void addLink(Link link) {
links.add(link);
}
/**
* Delete link.
*
* @param link needs to be deleted from list
*/
public void removeLink(Link link) {
links.remove(link);
}
}