use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class VirtualHostCodec method decode.
@Override
public VirtualHost decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
MacAddress mac = MacAddress.valueOf(json.get("mac").asText());
VlanId vlanId = VlanId.vlanId((short) json.get("vlan").asInt(VlanId.UNTAGGED));
Set<HostLocation> locations = new HashSet<>();
JsonNode locationNodes = json.get("locations");
locationNodes.forEach(locationNode -> {
PortNumber portNumber = PortNumber.portNumber(locationNode.get("port").asText());
DeviceId deviceId = DeviceId.deviceId(locationNode.get("elementId").asText());
locations.add(new HostLocation(deviceId, portNumber, 0));
});
HostId id = HostId.hostId(mac, vlanId);
Iterator<JsonNode> ipStrings = json.get("ipAddresses").elements();
Set<IpAddress> ips = new HashSet<>();
while (ipStrings.hasNext()) {
ips.add(IpAddress.valueOf(ipStrings.next().asText()));
}
return new DefaultVirtualHost(nId, id, mac, vlanId, locations, ips);
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class ResourceDeviceListener method registerPortResource.
private void registerPortResource(Device device, Port port) {
Resource portPath = Resources.discrete(device.id(), port.number()).resource();
if (!adminService.register(portPath)) {
log.error("Failed to register Port: {}", portPath.id());
}
queryBandwidth(device.id(), port.number()).map(bw -> portPath.child(Bandwidth.class, bw.bps())).map(adminService::register).ifPresent(success -> {
if (!success) {
log.error("Failed to register Bandwidth for {}", portPath.id());
}
});
// for VLAN IDs
Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
if (!vlans.isEmpty()) {
boolean success = adminService.register(vlans.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register VLAN IDs for {}", portPath.id());
}
}
// for MPLS labels
Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
if (!mplsLabels.isEmpty()) {
boolean success = adminService.register(mplsLabels.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register MPLS Labels for {}", portPath.id());
}
}
// for Lambdas
Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
if (!lambdas.isEmpty()) {
boolean success = adminService.register(lambdas.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register lambdas for {}", portPath.id());
}
}
// for Tributary slots
Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
if (!tSlots.isEmpty()) {
boolean success = adminService.register(tSlots.stream().map(portPath::child).collect(Collectors.toList()));
if (!success) {
log.error("Failed to register tributary slots for {}", portPath.id());
}
}
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class XmlParserCiscoTest method getExpectedIntfs.
private List<DeviceInterfaceDescription> getExpectedIntfs() {
List<DeviceInterfaceDescription> intfs = new ArrayList<>();
intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_1, DeviceInterfaceDescription.Mode.NORMAL, Lists.newArrayList(), NO_LIMIT, NO_RATE_LIMIT));
List<VlanId> accessList = new ArrayList<>();
accessList.add(ACCESS_VLAN);
intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_2, DeviceInterfaceDescription.Mode.ACCESS, accessList, NO_LIMIT, NO_RATE_LIMIT));
List<VlanId> trunkList1 = new ArrayList<>();
trunkList1.add(TRUNK_VLAN_1);
trunkList1.add(TRUNK_VLAN_2);
intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_3, DeviceInterfaceDescription.Mode.TRUNK, trunkList1, NO_LIMIT, NO_RATE_LIMIT));
intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_4, DeviceInterfaceDescription.Mode.NORMAL, Lists.newArrayList(), WITH_LIMIT, RATE_LIMIT_1));
List<VlanId> trunkList2 = new ArrayList<>();
trunkList2.add(TRUNK_VLAN_3);
trunkList2.add(TRUNK_VLAN_4);
trunkList2.add(TRUNK_VLAN_5);
intfs.add(new DefaultDeviceInterfaceDescription(INTF_NAME_5, DeviceInterfaceDescription.Mode.TRUNK, trunkList2, WITH_LIMIT, RATE_LIMIT_2));
return intfs;
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class InterfaceConfig method getInterfaces.
/**
* Retrieves all interfaces configured on this port.
*
* @return set of interfaces
* @throws ConfigException if there is any error in the JSON config
*/
public Set<Interface> getInterfaces() throws ConfigException {
Set<Interface> interfaces = Sets.newHashSet();
try {
for (JsonNode intfNode : array) {
String name = intfNode.path(NAME).asText(null);
List<InterfaceIpAddress> ips = getIps(intfNode);
String mac = intfNode.path(MAC).asText();
MacAddress macAddr = mac.isEmpty() ? null : MacAddress.valueOf(mac);
VlanId vlan = getVlan(intfNode, VLAN);
VlanId vlanUntagged = getVlan(intfNode, VLAN_UNTAGGED);
Set<VlanId> vlanTagged = getVlans(intfNode, VLAN_TAGGED);
VlanId vlanNative = getVlan(intfNode, VLAN_NATIVE);
interfaces.add(new Interface(name, subject, ips, macAddr, vlan, vlanUntagged, vlanTagged, vlanNative));
}
} catch (IllegalArgumentException e) {
throw new ConfigException(CONFIG_VALUE_ERROR, e);
}
return interfaces;
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class InterfaceCodec method decode.
@Override
public Interface decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String name = nullIsIllegal(json.findValue(NAME), NAME + MISSING_NAME_MESSAGE).asText();
ConnectPoint connectPoint = ConnectPoint.deviceConnectPoint(nullIsIllegal(json.findValue(CONNECT_POINT), CONNECT_POINT + MISSING_CONNECT_POINT_MESSAGE).asText());
List<InterfaceIpAddress> ipAddresses = Lists.newArrayList();
if (json.findValue(IPS) != null) {
json.findValue(IPS).forEach(ip -> {
ipAddresses.add(InterfaceIpAddress.valueOf(ip.asText()));
});
}
MacAddress macAddr = json.findValue(MAC) == null ? null : MacAddress.valueOf(json.findValue(MAC).asText());
VlanId vlanId = json.findValue(VLAN) == null ? VlanId.NONE : VlanId.vlanId(Short.parseShort(json.findValue(VLAN).asText()));
Interface inter = new Interface(name, connectPoint, ipAddresses, macAddr, vlanId);
return inter;
}
Aggregations