use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.Mac in project genius by opendaylight.
the class ArpUtilImpl method sendArpResponse.
@Override
public Future<RpcResult<Void>> sendArpResponse(SendArpResponseInput input) {
LOG.trace("sendArpResponse rpc invoked");
BigInteger dpnId;
byte[] payload;
byte[] srcMac;
try {
String interfaceName = input.getInterface();
GetPortFromInterfaceOutput portResult = getPortFromInterface(interfaceName);
checkNotNull(portResult);
dpnId = portResult.getDpid();
Long portid = portResult.getPortno();
NodeConnectorRef ref = MDSALUtil.getNodeConnRef(dpnId, portid.toString());
checkArgument(null != dpnId && !BigInteger.ZERO.equals(dpnId), ArpConstants.DPN_NOT_FOUND_ERROR, interfaceName);
checkNotNull(ref, ArpConstants.NODE_CONNECTOR_NOT_FOUND_ERROR, interfaceName);
LOG.trace("sendArpRequest received dpnId {} out interface {}", dpnId, interfaceName);
byte[] srcIpBytes = getIpAddressBytes(input.getSrcIpaddress());
byte[] dstIpBytes = getIpAddressBytes(input.getDstIpaddress());
if (input.getSrcMacaddress() == null) {
srcMac = portResult.getPhyAddress().getBytes("UTF-8");
} else {
String macAddr = input.getSrcMacaddress().getValue();
srcMac = HexEncode.bytesFromHexString(macAddr);
}
byte[] dstMac = NWUtil.parseMacAddress(input.getDstMacaddress().getValue());
checkNotNull(srcIpBytes, ArpConstants.FAILED_TO_GET_SRC_IP_FOR_INTERFACE, interfaceName);
payload = ArpPacketUtil.getPayload(ArpConstants.ARP_RESPONSE_OP, srcMac, srcIpBytes, dstMac, dstIpBytes);
List<Action> actions = getEgressAction(interfaceName);
sendPacketOutWithActions(dpnId, payload, ref, actions);
LOG.debug("Sent ARP response for IP {}, from source MAC {} to target MAC {} and target IP {} via dpnId {}", input.getSrcIpaddress().getIpv4Address().getValue(), HexEncode.bytesToHexStringFormat(srcMac), HexEncode.bytesToHexStringFormat(dstMac), input.getDstIpaddress().getIpv4Address().getValue(), dpnId);
} catch (UnknownHostException | PacketException | InterruptedException | UnsupportedEncodingException | ExecutionException e) {
LOG.error("failed to send arp response for {}: ", input.getSrcIpaddress(), e);
return RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, e.getMessage(), e).buildFuture();
}
RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.success();
return Futures.immediateFuture(rpcResultBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.Mac in project genius by opendaylight.
the class ArpUtilImpl method checkAndFireMacChangedNotification.
private void checkAndFireMacChangedNotification(String interfaceName, InetAddress inetAddr, byte[] macAddressBytes) throws InterruptedException {
IpAddress ip = new IpAddress(inetAddr.getHostAddress().toCharArray());
String macAddress = NWUtil.toStringMacAddress(macAddressBytes);
PhysAddress mac = new PhysAddress(macAddress);
if (!macAddress.equals(macsDB.get(interfaceName + "-" + inetAddr.getHostAddress()))) {
if (LOG.isTraceEnabled()) {
LOG.trace("mac address changed for {}", inetAddr);
}
MacChangedBuilder builder = new MacChangedBuilder();
builder.setInterface(interfaceName);
builder.setIpaddress(ip);
builder.setMacaddress(mac);
notificationPublishService.putNotification(builder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.Mac in project genius by opendaylight.
the class HwvtepSouthboundUtils method createRemoteMcastMac.
/**
* Creates the remote mcast mac.
*
* @param nodeId
* the node id
* @param mac
* the mac
* @param ipAddress
* the ip address
* @param logicalSwitchName
* the logical switch name
* @param lstPhysicalLocatorAug
* the lst physical locator aug
* @return the remote mcast macs
*/
public static RemoteMcastMacs createRemoteMcastMac(NodeId nodeId, String mac, IpAddress ipAddress, String logicalSwitchName, List<HwvtepPhysicalLocatorAugmentation> lstPhysicalLocatorAug) {
HwvtepLogicalSwitchRef lsRef = new HwvtepLogicalSwitchRef(createLogicalSwitchesInstanceIdentifier(nodeId, new HwvtepNodeName(logicalSwitchName)));
List<LocatorSet> lstLocatorSet = new ArrayList<>();
for (HwvtepPhysicalLocatorAugmentation phyLocatorAug : lstPhysicalLocatorAug) {
HwvtepPhysicalLocatorRef phyLocRef = new HwvtepPhysicalLocatorRef(createPhysicalLocatorInstanceIdentifier(nodeId, phyLocatorAug));
lstLocatorSet.add(new LocatorSetBuilder().setLocatorRef(phyLocRef).build());
}
RemoteMcastMacs remoteMcastMacs = new RemoteMcastMacsBuilder().setMacEntryKey(new MacAddress(mac)).setIpaddr(ipAddress).setLogicalSwitchRef(lsRef).setLocatorSet(lstLocatorSet).build();
return remoteMcastMacs;
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.Mac in project bgpcep by opendaylight.
the class MACIpAdvRParser method serializeBody.
@Override
public ByteBuf serializeBody(final EvpnChoice evpnChoice) {
Preconditions.checkArgument(evpnChoice instanceof MacIpAdvRouteCase, "Unknown evpn instance. Passed %s. Needed MacIpAdvRouteCase.", evpnChoice.getClass());
final ByteBuf body = Unpooled.buffer();
final MacIpAdvRoute evpn = ((MacIpAdvRouteCase) evpnChoice).getMacIpAdvRoute();
final Esi esi = evpn.getEsi();
if (esi != null) {
SimpleEsiTypeRegistry.getInstance().serializeEsi(evpn.getEsi(), body);
}
ByteBufWriteUtil.writeUnsignedInt(evpn.getEthernetTagId().getVlanId(), body);
final MacAddress mac = evpn.getMacAddress();
body.writeByte(MAC_ADDRESS_LENGTH * BITS_SIZE);
body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(mac));
final ByteBuf ipAddress = serializeIp(evpn.getIpAddress());
Preconditions.checkArgument(ipAddress.readableBytes() > 0);
body.writeBytes(ipAddress);
final MplsLabel mpls1 = evpn.getMplsLabel1();
if (mpls1 != null) {
body.writeBytes(byteBufForMplsLabel(mpls1));
}
final MplsLabel mpls2 = evpn.getMplsLabel2();
if (mpls2 != null) {
body.writeBytes(byteBufForMplsLabel(mpls2));
}
return body;
}
use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev140701.Mac in project bgpcep by opendaylight.
the class LacpParserTest method parserTest.
@Test
public void parserTest() {
final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
final LacpAutoGeneratedCase lanAuto = new LacpAutoGeneratedCaseBuilder().setLacpAutoGenerated(new LacpAutoGeneratedBuilder().setCeLacpMacAddress(MAC).setCeLacpPortKey(PORT).build()).build();
this.parser.serializeEsi(lanAuto, buff);
assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
assertEquals(lanAuto, acResult);
final ContainerNode cont = createContBuilder(new NodeIdentifier(LacpAutoGenerated.QNAME)).addChild(createValueBuilder(MAC_MODEL, LACP_MAC_NID).build()).addChild(createValueBuilder(PORT, PK_NID).build()).build();
final Esi acmResult = this.parser.serializeEsi(cont);
assertEquals(lanAuto, acmResult);
}
Aggregations