use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class BasicHostConfigTest method testConstruction.
/**
* Tests construction, setters and getters of a BasicHostConfig object.
*/
@Test
public void testConstruction() {
BasicHostConfig config = new BasicHostConfig();
ConfigApplyDelegate delegate = configApply -> {
};
ObjectMapper mapper = new ObjectMapper();
HostId hostId = NetTestTools.hid("12:34:56:78:90:ab/1");
IpAddress ip1 = IpAddress.valueOf("1.1.1.1");
IpAddress ip2 = IpAddress.valueOf("1.1.1.2");
IpAddress ip3 = IpAddress.valueOf("1.1.1.3");
Set<IpAddress> ips = ImmutableSet.of(ip1, ip2, ip3);
HostLocation loc1 = new HostLocation(NetTestTools.connectPoint("d1", 1), System.currentTimeMillis());
HostLocation loc2 = new HostLocation(NetTestTools.connectPoint("d2", 2), System.currentTimeMillis());
Set<HostLocation> locs = ImmutableSet.of(loc1, loc2);
HostLocation loc3 = new HostLocation(NetTestTools.connectPoint("d3", 1), System.currentTimeMillis());
HostLocation loc4 = new HostLocation(NetTestTools.connectPoint("d4", 2), System.currentTimeMillis());
Set<HostLocation> auxLocations = ImmutableSet.of(loc3, loc4);
VlanId vlanId = VlanId.vlanId((short) 10);
EthType ethType = EthType.EtherType.lookup((short) 0x88a8).ethType();
config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
config.setIps(ips).setLocations(locs).setAuxLocations(auxLocations).setInnerVlan(vlanId).setOuterTpid(ethType);
assertThat(config.isValid(), is(true));
assertThat(config.name(), is("-"));
assertThat(config.ipAddresses(), hasSize(3));
assertThat(config.ipAddresses(), hasItems(ip1, ip2, ip3));
assertThat(config.locations(), hasSize(2));
assertThat(config.locations(), hasItems(loc1, loc2));
assertThat(config.auxLocations(), hasSize(2));
assertThat(config.auxLocations(), hasItems(loc3, loc4));
assertThat(config.innerVlan(), is(vlanId));
assertThat(config.outerTpid(), is(ethType));
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method processDoubleVlanIdFilter.
/**
* Internal implementation of processDoubleVlanIdFilter.
*
* @param portCriterion port on device for which this filter is programmed
* @param innerVidCriterion inner vlan
* @param outerVidCriterion outer vlan
* @param popVlan true if outer vlan header needs to be removed
* @param applicationId for application programming this filter
* @return flow rules for port-vlan filters
*/
private List<FlowRule> processDoubleVlanIdFilter(PortCriterion portCriterion, VlanIdCriterion innerVidCriterion, VlanIdCriterion outerVidCriterion, boolean popVlan, ApplicationId applicationId) {
List<FlowRule> rules = new ArrayList<>();
TrafficSelector.Builder outerSelector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder outerTreatment = DefaultTrafficTreatment.builder();
TrafficSelector.Builder innerSelector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder innerTreatment = DefaultTrafficTreatment.builder();
VlanId outerVlanId = outerVidCriterion.vlanId();
VlanId innerVlanId = innerVidCriterion.vlanId();
PortNumber portNumber = portCriterion.port();
// Check arguments
if (PortNumber.ALL.equals(portNumber) || outerVlanId.equals(VlanId.NONE) || innerVlanId.equals(VlanId.NONE)) {
log.warn("Incomplete Filtering Objective. " + "VLAN Table cannot be programmed for {}", deviceId);
return ImmutableList.of();
} else {
outerSelector.matchInPort(portNumber);
innerSelector.matchInPort(portNumber);
outerTreatment.transition(VLAN_1_TABLE);
innerTreatment.transition(TMAC_TABLE);
outerTreatment.writeMetadata(outerVlanId.toShort(), 0xFFF);
outerSelector.matchVlanId(outerVlanId);
innerSelector.matchVlanId(innerVlanId);
// force recompilation
// FIXME might be issue due tu /fff mask
innerSelector.matchMetadata(outerVlanId.toShort());
if (popVlan) {
outerTreatment.popVlan();
}
}
// NOTE: for double-tagged packets, restore original outer vlan
// before sending it to the controller.
GroupKey groupKey = popVlanPuntGroupKey();
Group group = groupService.getGroup(deviceId, groupKey);
if (group != null) {
// push outer vlan and send to controller
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder().matchInPort(portNumber).matchVlanId(innerVlanId);
Host host = handler().get(HostService.class).getConnectedHosts(ConnectPoint.deviceConnectPoint(deviceId + "/" + portNumber.toLong())).stream().filter(h -> h.vlan().equals(outerVlanId)).findFirst().orElse(null);
EthType vlanType = EthType.EtherType.VLAN.ethType();
if (host != null) {
vlanType = host.tpid();
}
TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().pushVlan(vlanType).setVlanId(outerVlanId).punt();
rules.add(DefaultFlowRule.builder().forDevice(deviceId).withSelector(sbuilder.build()).withTreatment(tbuilder.build()).withPriority(PacketPriority.CONTROL.priorityValue()).fromApp(driverId).makePermanent().forTable(PUNT_TABLE).build());
} else {
log.info("popVlanPuntGroup not found in dev:{}", deviceId);
return Collections.emptyList();
}
FlowRule outerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(outerSelector.build()).withTreatment(outerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
FlowRule innerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(innerSelector.build()).withTreatment(innerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_1_TABLE).build();
rules.add(outerRule);
rules.add(innerRule);
return rules;
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class OvsOfdpaPipeline method processEgress.
/**
* In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
* egress tables.
* @param fwd the forwarding objective of type 'egress'
* @return a collection of flow rules to be sent to the switch. An empty
* collection may be returned if there is a problem in processing
* the flow rule
*/
@Override
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
List<FlowRule> rules = new ArrayList<>();
// Build selector
TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
if (vlanIdCriterion == null) {
log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof Instructions.OutputInstruction).findFirst();
if (!outInstr.isPresent()) {
log.error("Egress forwarding objective:{} must include output port", fwd.id());
fail(fwd, ObjectiveError.BADPARAMS);
return rules;
}
PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port();
sb.matchVlanId(vlanIdCriterion.vlanId());
OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
sb.extension(actsetOutput, deviceId);
// Build a flow rule for Egress VLAN Flow table
TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
tb.transition(UNICAST_ROUTING_TABLE_1);
if (fwd.treatment() != null) {
for (Instruction instr : fwd.treatment().allInstructions()) {
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
tb.immediate().add(instr);
}
if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
tb.immediate().pushVlan(ethType);
}
}
}
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
rules.add(ruleBuilder.build());
return rules;
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class NetworkConfigHostProvider method readInitialConfig.
private void readInitialConfig() {
networkConfigRegistry.getSubjects(HostId.class).forEach(hostId -> {
MacAddress mac = hostId.mac();
VlanId vlan = hostId.vlanId();
BasicHostConfig hostConfig = networkConfigRegistry.getConfig(hostId, BasicHostConfig.class);
Set<IpAddress> ipAddresses = hostConfig.ipAddresses();
Set<HostLocation> locs = hostConfig.locations();
if (locs != null) {
Set<HostLocation> locations = locs.stream().map(hostLocation -> new HostLocation(hostLocation, System.currentTimeMillis())).collect(Collectors.toSet());
// auxLocations allows to be null
Set<HostLocation> auxLocations = hostConfig.auxLocations();
if (auxLocations != null) {
auxLocations = auxLocations.stream().map(auxLocation -> new HostLocation(auxLocation, System.currentTimeMillis())).collect(Collectors.toSet());
}
VlanId innerVlan = hostConfig.innerVlan();
EthType outerTpid = hostConfig.outerTpid();
addHost(mac, vlan, locations, auxLocations, ipAddresses, innerVlan, outerTpid);
} else {
log.warn("Host {} configuration {} is missing locations", hostId, hostConfig);
}
});
}
use of org.onlab.packet.EthType in project onos by opennetworkinglab.
the class FlowEntryBuilder method configureTreatmentBuilder.
/**
* Configures traffic treatment builder with a given collection of actions.
*
* @param actions a set of OpenFlow actions
* @param builder traffic treatment builder
* @param driverHandler driver handler
* @param deviceId device identifier
* @return configured traffic treatment builder
*/
public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions, TrafficTreatment.Builder builder, DriverHandler driverHandler, DeviceId deviceId) {
ExtensionTreatmentInterpreter interpreter;
if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
} else {
interpreter = null;
}
for (OFAction act : actions) {
switch(act.getType()) {
case OUTPUT:
OFActionOutput out = (OFActionOutput) act;
builder.setOutput(PortNumber.portNumber(out.getPort().getPortNumber()));
break;
case SET_VLAN_VID:
OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
break;
case SET_VLAN_PCP:
OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
builder.setVlanPcp(pcp.getVlanPcp().getValue());
break;
case SET_DL_DST:
OFActionSetDlDst dldst = (OFActionSetDlDst) act;
builder.setEthDst(MacAddress.valueOf(dldst.getDlAddr().getLong()));
break;
case SET_DL_SRC:
OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
builder.setEthSrc(MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
break;
case SET_NW_DST:
OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
IPv4Address di = nwdst.getNwAddr();
builder.setIpDst(Ip4Address.valueOf(di.getInt()));
break;
case SET_NW_SRC:
OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
IPv4Address si = nwsrc.getNwAddr();
builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
break;
case EXPERIMENTER:
OFActionExperimenter exp = (OFActionExperimenter) act;
if (exp.getExperimenter() == 0x80005A06 || exp.getExperimenter() == 0x748771) {
OFActionCircuit ct = (OFActionCircuit) exp;
CircuitSignalID circuitSignalID = ((OFOxmOchSigid) ct.getField()).getValue();
builder.add(Instructions.modL0Lambda(Lambda.ochSignal(lookupGridType(circuitSignalID.getGridType()), lookupChannelSpacing(circuitSignalID.getChannelSpacing()), circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
} else if (interpreter != null) {
builder.extension(interpreter.mapAction(exp), deviceId);
} else {
log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
}
break;
case SET_FIELD:
OFActionSetField setField = (OFActionSetField) act;
handleSetField(builder, setField, driverHandler, deviceId);
break;
case POP_MPLS:
OFActionPopMpls popMpls = (OFActionPopMpls) act;
builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
break;
case PUSH_MPLS:
builder.pushMpls();
break;
case COPY_TTL_IN:
builder.copyTtlIn();
break;
case COPY_TTL_OUT:
builder.copyTtlOut();
break;
case DEC_MPLS_TTL:
builder.decMplsTtl();
break;
case DEC_NW_TTL:
builder.decNwTtl();
break;
case GROUP:
OFActionGroup group = (OFActionGroup) act;
builder.group(new GroupId(group.getGroup().getGroupNumber()));
break;
case SET_QUEUE:
OFActionSetQueue setQueue = (OFActionSetQueue) act;
builder.setQueue(setQueue.getQueueId());
break;
case ENQUEUE:
OFActionEnqueue enqueue = (OFActionEnqueue) act;
builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber()));
break;
case STRIP_VLAN:
case POP_VLAN:
builder.popVlan();
break;
case PUSH_VLAN:
OFActionPushVlan pushVlan = (OFActionPushVlan) act;
builder.pushVlan(new EthType((short) pushVlan.getEthertype().getValue()));
break;
case METER:
OFActionMeter actionMeter = (OFActionMeter) act;
builder.meter(MeterId.meterId(actionMeter.getMeterId()));
break;
case SET_TP_DST:
case SET_TP_SRC:
case POP_PBB:
case PUSH_PBB:
case SET_MPLS_LABEL:
case SET_MPLS_TC:
case SET_MPLS_TTL:
case SET_NW_ECN:
case SET_NW_TOS:
case SET_NW_TTL:
default:
log.warn("Action type {} not yet implemented.", act.getType());
}
}
return builder;
}
Aggregations