use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testMplsEncapsulationFilteredForMp.
/**
* We test the proper compilation of mp2sp with the MPLS
* encapsulation and filtered selector.
*/
@Test
public void testMplsEncapsulationFilteredForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForMPLS).links(linksForMp2Sp).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, vlan69Selector))).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, vlan200Selector), new FilteredConnectPoint(d2p10, vlan300Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(5));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan200Selector).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(2));
FlowRule ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p10.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(vlan300Selector).matchInPort(d2p10.port()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p0.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testCoLocatedFilteredPointsTrivialForSp.
/**
* We test the proper compilation of sp2mp with trivial selector,
* trivial treatment, mpls encapsulation and co-located
* filtered ingress/egress points.
*/
@Test
public void testCoLocatedFilteredPointsTrivialForSp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).applyTreatmentOnEgress(true).links(linksForSp2MpCoLoc).constraints(constraintsForMPLS).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, vlan200Selector), new FilteredConnectPoint(d2p10, vlan300Selector), new FilteredConnectPoint(d3p10, vlan69Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(1));
FlowRule ruleS1 = rulesS1.iterator().next();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d1p11.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(1));
FlowRule ruleS2 = rulesS2.iterator().next();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan300Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d2p10.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p1.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popMpls(IPV4.ethType()).pushVlan().setVlanId(((VlanIdCriterion) vlan69Selector.getCriterion(VLAN_VID)).vlanId()).setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class XmlParserCisco method getInterfacesFromConfig.
/**
* Parses device configuration and returns the descriptions of the device
* interfaces.
*
* @param cfg an hierarchical configuration
* @return list of interface descriptions for the device
*/
public static List<DeviceInterfaceDescription> getInterfacesFromConfig(HierarchicalConfiguration cfg) {
List<DeviceInterfaceDescription> intfs = Lists.newArrayList();
List<HierarchicalConfiguration> subtrees = cfg.configurationsAt("data.xml-config-data.Device-Configuration.interface");
for (HierarchicalConfiguration intfConfig : subtrees) {
String intfName = getInterfaceName(intfConfig);
DeviceInterfaceDescription.Mode intfMode = getInterfaceMode(intfConfig);
List<VlanId> intfVlans = getInterfaceVlans(intfConfig, intfMode);
short intfLimit = getInterfaceLimit(intfConfig);
boolean intfLimited = (intfLimit == NO_LIMIT ? false : true);
DeviceInterfaceDescription intf = new DefaultDeviceInterfaceDescription(intfName, intfMode, intfVlans, intfLimited, intfLimit);
intfs.add(intf);
}
return intfs;
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class ServerInterfaceConfig method getInterfaces.
@Override
public List<DeviceInterfaceDescription> getInterfaces() {
// Retrieve the device ID
DeviceId deviceId = getDeviceId();
checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
// .. and the device itself
RestServerSBDevice device = null;
try {
device = (RestServerSBDevice) getDevice(deviceId);
} catch (ClassCastException ccEx) {
log.error("Failed to get interfaces for device {}", deviceId);
return Collections.EMPTY_LIST;
}
if (device == null) {
log.error("No device with ID {} is available for interface discovery", deviceId);
return Collections.EMPTY_LIST;
}
if ((device.nics() == null) || (device.nics().size() == 0)) {
log.error("No interfaces available on {}", deviceId);
return Collections.EMPTY_LIST;
}
// List of port descriptions to return
List<DeviceInterfaceDescription> intfDescriptions = Lists.newArrayList();
// Sorted list of NIC ports
Set<NicDevice> nics = new TreeSet(device.nics());
// Iterate through the NICs of this device to populate the list
for (NicDevice nic : nics) {
List<VlanId> devVlanIds = getVlanIdListForDevice(nic);
Mode devMode = getDeviceMode(devVlanIds);
// Create an interface description and add it to the list
intfDescriptions.add(new DefaultDeviceInterfaceDescription(nic.name(), devMode, devVlanIds, RATE_LIMIT_STATUS, NO_LIMIT));
}
return ImmutableList.copyOf(intfDescriptions);
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class ServerInterfaceConfig method getVlanIdListForDevice.
/**
* Returns a list of VLAN IDs associated with a NIC device.
*
* @param nic the NIC device to be queried
* @return a list of VLAN IDs (if any)
*/
private List<VlanId> getVlanIdListForDevice(NicDevice nic) {
checkNotNull(nic, MSG_DEVICE_NULL);
List<VlanId> vlanIds = Lists.newArrayList();
short vlanIdValue = 0;
for (RxFilter rxFilter : nic.rxFilterMechanisms().rxFilters()) {
if (rxFilter == RxFilter.VLAN) {
vlanIds.add(VlanId.vlanId(vlanIdValue++));
}
}
return ImmutableList.copyOf(vlanIds);
}
Aggregations